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

Throw an error when response is unserializable #840

Merged
merged 3 commits into from Oct 11, 2022

Conversation

Mrtenz
Copy link
Member

@Mrtenz Mrtenz commented Oct 11, 2022

Previously, when a Snap would attempt to send an unserializable response, the stream would close with a cryptic error:

Error: PortDuplexStream - disconnected
  at PortDuplexStream._write (common-7.js:32090:23)
  at doWrite (common-8.js:42947:64)

This is because streams cannot serialize non-JSON-compatible values. I've added a check to make sure a response is serializable, and throw an error otherwise. Now, when a Snap tries to send an unserializable response, it will result in a more understandable JSON-RPC error:

{
  "code": -32603,
  "message": "JSON-RPC responses must be JSON serializable objects"
}

@Mrtenz Mrtenz requested a review from a team as a code owner October 11, 2022 10:10
@Mrtenz Mrtenz force-pushed the mrtenz/handle-unserializable-response branch from 7ab9fe8 to 39e5ce8 Compare October 11, 2022 10:25
@Mrtenz Mrtenz merged commit ed546b1 into main Oct 11, 2022
@Mrtenz Mrtenz deleted the mrtenz/handle-unserializable-response branch October 11, 2022 10:35
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.

None yet

2 participants