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

types: Make Data type-parameter optional in JsonRpcError #102

Merged
merged 3 commits into from
Aug 28, 2023

Conversation

legobeat
Copy link
Contributor

@legobeat legobeat commented Aug 23, 2023

This is in order to provide backwards-compatibility with code implemented towards v5.0.0. This fixes type errors introduced for TypeScript users in 5.1.0.

Resolves #100

Mrtenz
Mrtenz previously approved these changes Aug 23, 2023
Copy link
Member

@Mrtenz Mrtenz left a comment

Choose a reason for hiding this comment

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

Did you test that this fixes the type error in the other project?

@legobeat

This comment was marked as outdated.

@legobeat
Copy link
Contributor Author

Update: Made the error data optional in more places; MetaMask/json-rpc-engine#161 passes using this.

@legobeat legobeat requested a review from Mrtenz August 23, 2023 13:33
@legobeat legobeat marked this pull request as ready for review August 23, 2023 13:33
@legobeat legobeat requested a review from a team as a code owner August 23, 2023 13:33
@legobeat legobeat requested review from a team August 23, 2023 13:34
src/errors.ts Outdated
@@ -65,7 +68,7 @@ export const rpcErrors = {
* @param arg - The error message or options bag.
* @returns An instance of the {@link JsonRpcError} class.
*/
internal: <Data extends DataWithOptionalCause>(
internal: <Data extends OptionalDataWithOptionalCause>(
Copy link
Member

Choose a reason for hiding this comment

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

Since we're changing some RPC methods, should we just change it for all the methods?

This comment was marked as outdated.

Copy link
Contributor Author

@legobeat legobeat Aug 23, 2023

Choose a reason for hiding this comment

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

Going back, if we treat breaking types as breaking then we should make them all optional for now - then there will be the option of making things stricter in the next or an upcoming major.

I could think that perhaps ServerErrorOptions could be stricter then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR and MetaMask/json-rpc-engine#161 have been updated accordingly.

@legobeat legobeat requested a review from Mrtenz August 23, 2023 13:56
Mrtenz
Mrtenz previously approved these changes Aug 23, 2023
This is in order to provide backwards-compatibility with code
implemented towards v5.0.0.
@legobeat
Copy link
Contributor Author

Rebased after #103; MetaMask/json-rpc-engine#161 synced.

@legobeat legobeat requested a review from a team August 23, 2023 14:36
Mrtenz
Mrtenz previously approved these changes Aug 23, 2023
@legobeat
Copy link
Contributor Author

Digging at MetaMask/providers#253 (similar upgrade error in other package), it seems like there's some drifting in @metamask/utils also related to this.

#101

MetaMask/utils#129

MetaMask/utils#130

@legobeat legobeat requested a review from rekmarks August 24, 2023 05:58
* - A valid DataWithOptionalCause value.
* - undefined.
*/
export type OptionalDataWithOptionalCause = undefined | DataWithOptionalCause;
Copy link
Member

Choose a reason for hiding this comment

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

Won't these changes cause issues elsewhere because they aren't valid JSON? Goes for both changes in this file

Copy link
Contributor Author

@legobeat legobeat Aug 28, 2023

Choose a reason for hiding this comment

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

The first one should be as fine as it gets, I think.

The one, here, though, I am less confident due to undefined being listed here.

Would it be possible to construct a failure case/regression/validating use-case of some sort? Also, how hard should type-only breakages actually be considered (as they are optional and don't actually affect runtime outcome)?

I'm really struggling to unbreak downstreams in any other way which doesn't cause new detectable inconsistencies and type errors but open to suggestions.

Copy link
Member

Choose a reason for hiding this comment

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

Actually this should be fine I think. We have serializeError for turning the classes into serializable JSON errors, so having undefined in the class is fine.

@legobeat legobeat merged commit 2b0bcbd into MetaMask:main Aug 28, 2023
16 checks passed
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.

Provide compatible types for v5.x
3 participants