Skip to content

rpc: support wrapped errors and code-based Is for jsonError#649

Open
pmikolajczyk41 wants to merge 1 commit intomasterfrom
pmikolajczyk/nit-4738-json-rpc-errors
Open

rpc: support wrapped errors and code-based Is for jsonError#649
pmikolajczyk41 wants to merge 1 commit intomasterfrom
pmikolajczyk/nit-4738-json-rpc-errors

Conversation

@pmikolajczyk41
Copy link
Copy Markdown
Member

  1. errorMessage previously cast err directly to rpc.Error/DataError, which missed errors wrapped with fmt.Errorf("%w", ...). Switch to errors.As so the code and data are extracted correctly from wrapped errors.
  2. Add (*jsonError).Is so that errors.Is(receivedErr, sentinel) works on the client side when receivedErr is a jsonError reconstructed from the wire. Matching is by error code: if the sentinel implements ErrorCode() int, the codes are compared. This avoids the need for string-based error reconstruction in callers.

pulled in by OffchainLabs/nitro#4629

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