Skip to content

chore: normalize wallet invocation errors across transports#312

Open
wenfix wants to merge 10 commits into
mainfrom
wapi-1521
Open

chore: normalize wallet invocation errors across transports#312
wenfix wants to merge 10 commits into
mainfrom
wapi-1521

Conversation

@wenfix
Copy link
Copy Markdown
Contributor

@wenfix wenfix commented May 28, 2026

Explanation

connect-multichain.invokeMethod() could surface different error shapes depending on whether a wallet error arrived as a resolved JSON-RPC error response or as a rejected transport error. That also meant connect-evm could lose provider-facing details when adapting multichain errors to EIP-1193 request errors.

This change normalizes wallet invocation failures at the RequestRouter boundary:

  • extracts wallet code, message, and JSON-RPC data from response errors and wrapped transport errors
  • walks a capped cause chain so transport/API wrappers do not hide the wallet error
  • wraps normalized wallet failures in RPCInvokeMethodErr while preserving reason, rpcCode, rpcMessage, and rpcData
  • keeps existing RPCInvokeMethodErr instances unchanged
  • keeps analytics classification using normalized wallet codes while preserving original uncoded transport errors for transport diagnostics

connect-evm now maps normalized RPCInvokeMethodErr instances into EIP-1193-facing errors that carry the wallet code, provider-facing message, and JSON-RPC data when present.

References

  • WAPI-1521

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed, highlighting breaking changes as necessary
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

@wenfix wenfix requested a review from a team as a code owner May 28, 2026 14:17
@wenfix wenfix changed the title Normalize wallet invocation errors across transports chore: normalize wallet invocation errors across transports May 28, 2026
mockCore.invokeMethod.mockRejectedValue(
new RPCInvokeMethodErr(
'RPC Request failed with code 4001: User denied transaction signature.',
'User rejected the request',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

User rejected the request.

);
const ancestorMessage = getFirstNonEmptyMessage([
primitiveMessage,
...ancestorObjects.map((object) => object.message),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not certain it makes sense to try to resolve an error message from earlier up in the chain. Hard for me to fully understand this problem though. What were your thoughts around this?

* @param error - Unknown error thrown or returned during method execution.
* @returns Canonical fields for RPCInvokeMethodErr.
*/
function getInvocationErrorDetails(error: unknown): InvocationErrorDetails {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thoughts on moving all these newly added error helpers into their own file?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quite a bit of complexity in this helper. How deeply nested are we expecting causes to be?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems unrelated to this main purpose of this PR

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems unrelated to this main purpose of this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants