core icon indicating copy to clipboard operation
core copied to clipboard

[json-rpc-engine] Improve handling for unexpected middleware error types, align error types to use `JsonRpcEngineCallbackError`

Open MajorLift opened this issue 1 year ago • 1 comments

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, 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

MajorLift avatar Mar 07 '24 03:03 MajorLift

@MajorLift is this effectively resolved by #6176?

rekmarks avatar Nov 09 '25 01:11 rekmarks