feat: Preserve original messages during error serialization by default#158
Merged
feat: Preserve original messages during error serialization by default#158
Conversation
10 tasks
Contributor
|
This is being incorporated in mm extension here: |
legobeat
previously approved these changes
Oct 8, 2024
src/utils.ts
Outdated
| const cause = serializeCause(error); | ||
| const fallbackWithCause = { | ||
| ...fallbackError, | ||
| ...(originalMessage && { message: originalMessage }), |
Member
There was a problem hiding this comment.
Can we add shouldPreserveMessage = true to the options in serializeError and only use this behavior if it is true?
Member
Author
There was a problem hiding this comment.
Done: cb3a6b4
I fixed a number of annoying formatting things with the errors, but only added one case for the new param.
rekmarks
commented
Oct 8, 2024
Comment on lines
+227
to
+243
| 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, | ||
| }, | ||
| }, | ||
| }); | ||
| }); |
Member
Author
There was a problem hiding this comment.
This is the only addition to this file.
FrederikBolding
approved these changes
Oct 8, 2024
This was referenced Oct 9, 2024
This was referenced Oct 9, 2024
Closed
Gudahtt
pushed a commit
to legobeat/metamask-extension
that referenced
this pull request
Oct 16, 2024
MetaMask/rpc-errors#158 - Update test according to new @metamask/rpc-errors behavior This partially reverts commit aeca6d797fc16d13bcd16f8649159769207ede78.
Gudahtt
pushed a commit
to MetaMask/metamask-extension
that referenced
this pull request
Oct 16, 2024
…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. [](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.
Gudahtt
pushed a commit
to MetaMask/metamask-extension
that referenced
this pull request
Oct 21, 2024
…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. [](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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This ensures that non-empty string
error.messageproperties 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
messageproperty 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 themessageproperty 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).