handshake-org/hs-client

Unhandled AssertionError on the RPC endpoint

gdassori opened this issue · 2 comments

The bcurl API raises an assertion error when an empty method is passed to the RPC execute method (https://github.com/bcoin-org/bcurl/blob/master/lib/client.js#L310).

The way the execute is used in the hsd and hsw client (super().execute) throw this bad exception right as a client response, when passing an empty method to the rpc command:

$ ./bin/hsd-cli rpc
AssertionError [ERR_ASSERTION]: Assertion failed.

This could be both a problem of bcurl, that doesn't throw an RPCError exception, or of the hs-client, that should catch the raw assertion and throw the error.

Knowing nothing, I tend to think that bcurl developers thought the execute method as private.

Intially I thought that a way to fix this could be to call the super().execute() inside a try\catch, and raise an RPCError.. but the RPCError is not exported by the client module, so I went into a loop and back to think as a bcurl "issue" (at least the dependency should be changed to export the class).

What do you think?

Seems like we should be able to catch this mistake further up, maybe throwing an error in hsd-cli itself here if method is null:

const method = this.argv.shift();

and in hsw-cli here:

const method = this.argv.shift();

Closed by #42