json-rpc-engine
json-rpc-engine copied to clipboard
WIP: Improve middleware errors
Pending: MetaMask/json-rpc-engine#83
This attempts to address some of the concerns raised in MetaMask/core#1993, regarding the throwing of non-Error values. It doesn't fully resolve the issue, because the async signatures of engine.handle will never reject, and will only pass through middleware errors as plain object clones, without a stack property. The callback signature of engine.handle receives the thrown error as the first argument, in the style of Node.js.
TODO
- Figure out what to do with error stacks. See comments.
I'm considering how we can return the full, native Error object to the caller via the Promise-based engine.handle signatures. We can't cause engine.handle to reject because we need to pass a JSON-RPC response to the caller. A few options come to mind:
- Preserve the
stackproperty on the plain object clone. We could make this behavior configurable. We removed it in the first place to avoid sending useless production stacks to external domains. - Assign the native
Errorobject toresponse.error, and leave serialization to a different layer. - Make the
asyncsignatures ofengine.handlereturn something likePromise<[Error, response]>. I think I hate this, but will put it out there nonetheless.
This library has now been migrated into the core monorepo. This PR has been locked and this repo will be archived shortly. Going forward, releases of this library will only include changes made in the core repo.
- Please push this branch to core and open a new PR there.
- Optionally, add a link pointing to the discussion in this PR to provide context.