Skip to content
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

Rewrite error serialization #61

Merged
merged 15 commits into from
Apr 11, 2023
Merged

Conversation

FrederikBolding
Copy link
Member

@FrederikBolding FrederikBolding commented Oct 27, 2022

Rewrite error serialization to allow any error that conforms to the JsonRpcError JSON-compliant type.

If the error does not conform to this type, it will be wrapped in an Internal RPC error and the original error will be included as the data.cause. Any non JSON-compliant props of the error will be removed.

Fixes #51

@FrederikBolding FrederikBolding force-pushed the fb/fix-error-serialization branch 4 times, most recently from 4fac448 to d92428b Compare November 2, 2022 12:02
@FrederikBolding FrederikBolding changed the title Fix error serialization Rewrite error serialization Nov 3, 2022
@rekmarks rekmarks self-assigned this Nov 10, 2022
@FrederikBolding FrederikBolding dismissed a stale review via 132112f March 9, 2023 10:06
@FrederikBolding FrederikBolding force-pushed the fb/fix-error-serialization branch from 132112f to 5a145b0 Compare March 9, 2023 10:08
@FrederikBolding FrederikBolding marked this pull request as ready for review March 9, 2023 10:18
@FrederikBolding FrederikBolding requested a review from a team as a code owner March 9, 2023 10:18
// 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,
Copy link
Member

Choose a reason for hiding this comment

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

drops non enumerable properties

Copy link
Member Author

Choose a reason for hiding this comment

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

What would you prefer then? Setting enumerable to true for fallbackError?

Copy link
Member Author

Choose a reason for hiding this comment

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

In my opinion, this wouldn't be an issue since we specify the fallback error and it includes the cause that may still have a stack.

Copy link
Member

Choose a reason for hiding this comment

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

Presumably what we'd want to do here is preserve the fallbackError as much as possible, mutating it only to add the cause property.

In this case the fallback error is already expected to be a "serializable object" though, right? So maybe we don't need to worry about non-enumerable properties. Though the JSDoc description should certainly clarify that expectation if that is the case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I would expect it to be serializable according to the type. I can add it to the doc string

@socket-security
Copy link

New dependency changes detected. Learn more about Socket for GitHub ↗︎


👍 No new dependency issues detected in pull request

Bot Commands

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of package-name@version specifiers. e.g. @SocketSecurity ignore [email protected] bar@* or ignore all packages with @SocketSecurity ignore-all

Pull request alert summary
Issue Status
Install scripts ✅ 0 issues
Native code ✅ 0 issues
Bin script shell injection ✅ 0 issues
Unresolved require ✅ 0 issues
Invalid package.json ✅ 0 issues
HTTP dependency ✅ 0 issues
Git dependency ✅ 0 issues
Potential typo squat ✅ 0 issues
Known Malware ✅ 0 issues
Telemetry ✅ 0 issues
Protestware/Troll package ✅ 0 issues

📊 Modified Dependency Overview:

⬆️ Updated Package Version Diff Added Capability Access +/- Transitive Count Publisher
@metamask/[email protected] 3.6.0...5.0.0 network +47/-0 metamaskbot
[email protected] 4.7.4...4.9.5 network, shell, environment +0/-0 typescript-bot

Gudahtt
Gudahtt previously approved these changes Apr 11, 2023
Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM!

@FrederikBolding FrederikBolding merged commit 8191913 into main Apr 11, 2023
@FrederikBolding FrederikBolding deleted the fb/fix-error-serialization branch April 11, 2023 13:00
rekmarks added a commit that referenced this pull request Oct 8, 2024
#158)

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](https://www.jsonrpc.org/specification#error_object). This
behavior can be overridden by setting `shouldPreserveMessage: 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 the
`message` 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 in
`error.data.cause.message`).
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.

Error serialization logic is faulty
5 participants