-
-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Preserve original messages during error serialization by default #158
Conversation
This is being incorporated in mm extension here: |
src/utils.ts
Outdated
// If the error does not match the JsonRpcError type, use the fallback error, but try to include the original error as `cause`. | ||
const cause = serializeCause(error); | ||
const fallbackWithCause = { | ||
...fallbackError, | ||
...(originalMessage && { message: originalMessage }), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add shouldPreserveMessage = true
to the options in serializeError
and only use this behavior if it is true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done: cb3a6b4
I fixed a number of annoying formatting things with the errors, but only added one case for the new param.
it('overwrites the original message with `shouldPreserveMessage: false`', () => { | ||
const error = new Error('foo'); | ||
const result = serializeError(error, { | ||
shouldPreserveMessage: false, | ||
fallbackError: validError0, | ||
}); | ||
expect(result).toStrictEqual({ | ||
code: validError0.code, | ||
message: validError0.message, | ||
data: { | ||
cause: { | ||
message: error.message, | ||
stack: error.stack, | ||
}, | ||
}, | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only addition to this file.
MetaMask/rpc-errors#158 - Update test according to new @metamask/rpc-errors behavior This partially reverts commit aeca6d7.
MetaMask/rpc-errors#158 - Update test according to new @metamask/rpc-errors behavior This partially reverts commit aeca6d7.
MetaMask/rpc-errors#158 - Update test according to new @metamask/rpc-errors behavior This partially reverts commit aeca6d7.
MetaMask/rpc-errors#158 - Update test according to new @metamask/rpc-errors behavior This partially reverts commit aeca6d7.
MetaMask/rpc-errors#158 - Update test according to new @metamask/rpc-errors behavior This partially reverts commit aeca6d7.
MetaMask/rpc-errors#158 - Update test according to new @metamask/rpc-errors behavior This partially reverts commit aeca6d7.
MetaMask/rpc-errors#158 - Update test according to new @metamask/rpc-errors behavior This partially reverts commit aeca6d7.
MetaMask/rpc-errors#158 - Update test according to new @metamask/rpc-errors behavior This partially reverts commit aeca6d7.
MetaMask/rpc-errors#158 - Update test according to new @metamask/rpc-errors behavior This partially reverts commit aeca6d7.
MetaMask/rpc-errors#158 - Update test according to new @metamask/rpc-errors behavior This partially reverts commit aeca6d7.
MetaMask/rpc-errors#158 - Update test according to new @metamask/rpc-errors behavior This partially reverts commit aeca6d7.
…edition) (#24496) ## **Description** - Upgrade from obsolete `eth-rpc-errors` to `@metamask/rpc-errors` - This introduce handling of error causes See [here](MetaMask/rpc-errors#140) for some context. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/24496?quickstart=1) ## **Related issues** - #22871 #### Blocked by - [x] MetaMask/rpc-errors#158 - [x] MetaMask/rpc-errors#144 - [x] MetaMask/rpc-errors#140 #### Blocking - #22875 ## **Manual testing steps** ## **Screenshots/Recordings** ### **Before** ### **After** ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
…edition) (#24496) - Upgrade from obsolete `eth-rpc-errors` to `@metamask/rpc-errors` - This introduce handling of error causes See [here](MetaMask/rpc-errors#140) for some context. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/24496?quickstart=1) - #22871 - [x] MetaMask/rpc-errors#158 - [x] MetaMask/rpc-errors#144 - [x] MetaMask/rpc-errors#140 - #22875 - [x] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
This ensures that non-empty string
error.message
properties of serialized errors are preserved by default, even if the serialized error is not a valid JSON-RPC error. This behavior can be overridden by settingshouldPreserveMessage: false
.In #61, our error serialization logic was considerably improved. One of the behavioral changes made at the time was to always overwrite the
message
property with that of the fallback error (practically always the "internal JSON-RPC-error"), regardless of whether a non-empty string message was present on the original error object. We have yet to ship this everywhere in our stack, in part because such a change may be breaking for our consumers. By reverting to the old behavior for themessage
property only, we avoid these potential breakages and improve the accessibility of potentially useful information to consumers (i.e. directly in the error message as opposed to buried inerror.data.cause.message
).