[json-rpc-engine] Improve handling for unexpected middleware error types, align error types to use `JsonRpcEngineCallbackError`
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 413
- Forks
- 308
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 253
Description
## Motivation
Currently, `JsonRpcEngine` handles non-JSON-RPC errors thrown from middleware by passing them into `end` callbacks without validation or serialization.
Fixing this is necessary to take full advantage of the [provider alignment technical proposals](https://app.zenhub.com/workspaces/shared-libraries-621e46b4d7103800171d1b02/issues/zh/244), as `JsonRpcEngine` is the call site for the provider methods. A more accurately typed `JsonRpcEngine` would enable us to make potential typing improvements to the providers as well.
## Explanation
The code for handling these errors suppresses valid errors by using type assertions (`as JsonRpcEngineCallbackError`), despite their being no guarantee that the thrown errors will be of that type. These assertions (currently marked by TODO comments) should be removed and replaced with type-safe code.
We should align error types used throughout middleware the chain with the `JsonRpcEngineCallbackError` type. This may involve coming up with a scheme for lossless serialization of errors that explicitly preserves information that is expected by `JsonRpcEngine`.
## References
- Follows from https://github.com/MetaMask/core/issues/3720
- Left 3 TODOs in the `JsonRpcEngine` class
- See previous effort https://github.com/MetaMask/json-rpc-engine/pull/84
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the JsonRpcEngine class and its three TODOs around middleware error handling, then review the related discussion in issue 3720 and pull request 84. Determine how thrown errors should be represented as JsonRpcEngineCallbackError values without losing expected information; done means the unsafe type assertions are removed and middleware error types are aligned.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, backend-api-design
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100