Skip to content

fix(deps): update from eth-rpc-errors to @metamask/rpc-errors#22871

Closed
legobeat wants to merge 17 commits intoMetaMask:developfrom
legobeat:deps-eth-rpc-errors
Closed

fix(deps): update from eth-rpc-errors to @metamask/rpc-errors#22871
legobeat wants to merge 17 commits intoMetaMask:developfrom
legobeat:deps-eth-rpc-errors

Conversation

@legobeat
Copy link
Copy Markdown
Contributor

@legobeat legobeat commented Feb 8, 2024

Description

The package eth-rpc-errors has been renamed to @metamask/rpc-errors starting with version 5. Many controllers and libraries used in extension already use the releases. This updates the direct dependency from eth-rpc-errors@4.0.2 to @metamask/rpc-errors@6.0.1.

Related issues

Blocking

Manual testing steps

Screenshots/Recordings

Before

After

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • I've clearly explained what problem this PR is solving and how it is solved.
  • I've linked related issues
  • I've included manual testing steps
  • I've included screenshots/recordings if applicable
  • I’ve included tests if applicable
  • I’ve documented my code using JSDoc format if applicable
  • I’ve applied the right labels on the PR (see labeling guidelines). Not required for external contributors.
  • I’ve properly set the pull request status:
    • In case it's not yet "ready for review", I've set it to "draft".
    • In case it's "ready for review", I've changed it from "draft" to "non-draft".

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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 8, 2024

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@legobeat legobeat force-pushed the deps-eth-rpc-errors branch from 31e4a2a to b075fa9 Compare February 8, 2024 10:18
@legobeat legobeat added dependencies Pull requests that update a dependency file team-application-security Application security team labels Feb 8, 2024
@FrederikBolding
Copy link
Copy Markdown
Member

🎉

FrederikBolding
FrederikBolding previously approved these changes Feb 8, 2024
Copy link
Copy Markdown
Member

@FrederikBolding FrederikBolding left a comment

Choose a reason for hiding this comment

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

Code LGTM, but looks to be some problems in CI.

@legobeat
Copy link
Copy Markdown
Contributor Author

legobeat commented Feb 8, 2024

Code LGTM, but looks to be some problems in CI.

Addressed in c81c5033101e32f68b011d9ab91db76db39eff5d by updating tests to expect underlying error message in cause.

@legobeat legobeat marked this pull request as ready for review February 8, 2024 11:41
@legobeat legobeat requested review from a team as code owners February 8, 2024 11:41
FrederikBolding
FrederikBolding previously approved these changes Feb 8, 2024
@legobeat legobeat marked this pull request as draft February 8, 2024 12:15
@legobeat legobeat force-pushed the deps-eth-rpc-errors branch 7 times, most recently from 5d38fdd to 4284831 Compare February 8, 2024 18:50
@legobeat legobeat force-pushed the deps-eth-rpc-errors branch 2 times, most recently from 79e9598 to 7f3572e Compare February 22, 2024 04:34
@legobeat legobeat changed the title deps: update from eth-rpc-errors to @metamask/rpc-errors fix(deps): update from eth-rpc-errors to @metamask/rpc-errors Feb 23, 2024
@legobeat legobeat force-pushed the deps-eth-rpc-errors branch 3 times, most recently from b82f0e9 to d09d8f7 Compare March 11, 2024 01:14
@legobeat legobeat force-pushed the deps-eth-rpc-errors branch from d09d8f7 to 892b0cc Compare April 18, 2024 23:13
@legobeat legobeat force-pushed the deps-eth-rpc-errors branch 4 times, most recently from 59af259 to a385eb3 Compare May 7, 2024 11:19
kumavis
kumavis previously approved these changes May 9, 2024
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

seems like a good idea

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, wouldn't this be the correct type? It's one or the other, not necessarily both

Suggested change
): error is { message: string } & { data: { cause: { message: string } } } {
): error is { message: string } | { data: { cause: { message: string } } } {

Comment on lines 18 to 20
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can avoid using any by using our hasProperty and isObject functions from @metamask/utils:

Suggested change
('message' in error ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
typeof (error as any)?.data?.cause?.message === 'string')
(hasProperty(error, 'message') ||
(hasProperty(error, 'data') &&
isObject(error.data) &&
hasProperty(error.data, 'cause') &&
isObject(error.data.cause) &&
hasProperty(error.data.cause, 'message') &&
typeof error.data.cause.message === 'string'))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nice, will update accordingly!

Copy link
Copy Markdown
Contributor Author

@legobeat legobeat May 9, 2024

Choose a reason for hiding this comment

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

Looping back: Why is the suggestion preferred, actually? In this case it doesn't give us any further benefits wrt types or guarantees from the type system (I think?), and the ?. is a lot easier to read. If it's just because "any bad", I'd actually think it's actually intended for situations like this? Unless I'm indeed overlooking something!

(Looks like this part will still be rewritten anyway, though, as consequence of properly fixing types)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

any will disable type checking completely, anywhere the value set to any is used (including any derived types). It can easily "infect" the rest of the codebase in subtle ways, preventing type checking where we might otherwise expect it. I don't think there are any situations where we found any to be the best choice for a parameter/value/etc (the only "non-harmful" case we found was in generic type constraints, where it can't spread any further).

See more on recommended escape hatches here: https://github.com/MetaMask/contributor-docs/blob/main/docs/typescript.md#escape-hatches

Though in this case, it does add type safety. This statement wasn't typed before, now it is.

I see your point about ?. being a lot easier to read. This has been one of my biggest frustrations with TypeScript, that it makes it difficult and verbose to interact with data structures that you don't know the contents of ahead of time. Any reference to an unrecognized property causes complaint, you need to first hold TypeScript's hand through the process of looking for that property first (hence the hasProperty type guard). There is probably a better way of doing this that I'm not aware of.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Def agree in the general, but here it's "enclosed" and the line has the same out-and-in types as those 6 lines...

Regardless of approach, the equivalent in my currently preferred approach over this one becomes a bit less lengthy: https://github.com/MetaMask/metamask-extension/pull/24496/files#diff-b9515eba7ccebd6c2cb33172f8f348816351594c12a5eebe825a573c9b8f59b0R22

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This could make the test more flaky, as we're introducing two new async steps in between finding the element and asserting. The element could be found, then removed from the DOM or had its contents changed.

Copy link
Copy Markdown
Contributor Author

@legobeat legobeat May 9, 2024

Choose a reason for hiding this comment

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

While true, if this is the case, wouldn't that be indicative of an actual error we do want to fail (ideally consistently, since that should never happen right?)

But anyway, I can take a look at if this can work again with only a single async like before.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's true that the type of page behavior that would trigger flakiness in this case is probably undesirable.

But we do have UI that is meant to refresh (e.g. gas estimates, balances, the activity list, etc.). And we have a lot of janky UI that rerenders when it shouldn't, causing flakiness in cases like this, where it would be helpful for the test to assert something about the UI behavior even in the face of this problem.

Hmm. Tricky problem. Maybe you're right that having tests that are less-tolerant of jankyness would encourage us to fix the jankyness. But given the current state of our e2e test suite, my intuition is that it would do more harm than good in the short/medium term because we don't have capacity to do a good job of fixing janky UI everywhere right now, and we desperately need our tests to be less flaky. But I am definitely open to being convinced otherwise here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, it's not clear what could have necessitated this change

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Leftover from WIP attempts, I think. Will see if these can be reverted to keep the changes relevant.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: We should be able to avoid a cast here as well, by using hasProperty and isObject from @metamask/utils

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Sep 2, 2024

This PR has been automatically marked as stale because it has not had recent activity in the last 60 days. It will be closed in 14 days. Thank you for your contributions.

@github-actions
Copy link
Copy Markdown
Contributor

This PR was closed because there has been no follow up activity in the last 14 days. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file stale issues and PRs marked as stale team-application-security Application security team

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants