json-rpc-engine icon indicating copy to clipboard operation
json-rpc-engine copied to clipboard

WIP: Improve middleware errors

Open rekmarks opened this issue 4 years ago • 2 comments

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.

rekmarks avatar Mar 29 '21 00:03 rekmarks

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:

  1. Preserve the stack property 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.
  2. Assign the native Error object to response.error, and leave serialization to a different layer.
  3. Make the async signatures of engine.handle return something like Promise<[Error, response]>. I think I hate this, but will put it out there nonetheless.

rekmarks avatar Mar 29 '21 03:03 rekmarks

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.

MajorLift avatar Nov 07 '23 17:11 MajorLift