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

Add PendingJsonRpcResponse type #43

Merged
merged 2 commits into from Oct 6, 2022
Merged

Conversation

Mrtenz
Copy link
Member

@Mrtenz Mrtenz commented Oct 6, 2022

Closes #39.

This adds a type and validation for PendingJsonRpcResponse.

@Mrtenz Mrtenz requested a review from a team as a code owner October 6, 2022 13:30
Comment on lines +698 to +707
{
id: 1,
jsonrpc: '2.0',
result: {
foo: 'bar',
},
error: {
code: -32000,
message: 'Internal error',
},
Copy link
Member Author

Choose a reason for hiding this comment

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

The original type in @metamask/types allows this. Please verify that this is intended, as I'm not sure where PendingJsonRpcResponse is used.

Copy link
Contributor

Choose a reason for hiding this comment

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

It appears that this is intended behavior. PendingJsonRpcResponse was created to represent a response object within middleware. The idea here is that while a request is being sent through layers of a middleware stack, we don't know what the final response object will be — we don't know whether it will end up representing a successful or failed response. So PendingJsonRpcResponse is like the Schrodinger's cat of responses. It looks like the possibility that both result and error could be set was acknowledged but accepted as a compromise to prevent from having to typecast the response in middleware: MetaMask/json-rpc-engine#75

@Mrtenz Mrtenz force-pushed the mrtenz/pending-json-rpc-response branch from 1595860 to d0479d0 Compare October 6, 2022 15:31
Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

LGTM.

@Mrtenz Mrtenz merged commit c971d54 into main Oct 6, 2022
@Mrtenz Mrtenz deleted the mrtenz/pending-json-rpc-response branch October 6, 2022 16:59
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.

Add PendingJsonRpcResponse
2 participants