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

Gracefully handle requesting gas fee estimates for nonexistent network #5084

Closed

Conversation

mcmire
Copy link
Contributor

@mcmire mcmire commented Dec 19, 2024

Explanation

Currently, when GasFeeController tries to fetch gas fee estimates for a network that does not exist for some reason, it consults NetworkController for the corresponding network client and then NetworkController throws an error.

It could be argued that we don't really care that the network doesn't exist and there is no reason to expose this information to the client. Given this assumption, this commit gracefully handles this situation by returning an empty set of estimates instead.

References

There are a series of errors in Sentry for both Extension and Mobile which refer to the uncaught error:

This fix would prevent those errors from occurring.

Changelog

(Updated in PR.)

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

@mcmire mcmire force-pushed the handle-nonexistent-network-client-when-fetching-estimates branch from 8188720 to 26a8094 Compare December 19, 2024 20:12
@mcmire
Copy link
Contributor Author

mcmire commented Dec 19, 2024

I guess the question for this PR would be whether it makes sense to hide the error? @bergeron highlighted a scenario in which it could happen and proposed an alternative here, and a fix was made to the extension. But I am wondering whether that fix should be reverted and this fix works better?

@mcmire mcmire force-pushed the handle-nonexistent-network-client-when-fetching-estimates branch from 26a8094 to 441df67 Compare December 19, 2024 20:19
Currently, when GasFeeController tries to fetch gas fee estimates for a
network that does not exist for some reason, it consults
NetworkController for the corresponding network client and then
NetworkController throws an error.

It could be argued that we don't really care that the network doesn't
exist and there is no reason to expose this information to the client.
Given this assumption, this commit gracefully handles this situation by
returning an empty set of estimates instead. It also extracts the error
message produced when a network client is not found so that it can be
checked more easily.
@mcmire mcmire force-pushed the handle-nonexistent-network-client-when-fetching-estimates branch from 441df67 to f92f1c7 Compare December 19, 2024 20:40
@mcmire mcmire marked this pull request as ready for review December 19, 2024 20:47
@mcmire mcmire requested review from a team as code owners December 19, 2024 20:47
);
} catch (error) {
if (error instanceof NoNetworkClientFoundError) {
log(error.message);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I figured that we ought to be aware of the problem on some level, I am just unsure what the best place is.

@Gudahtt What would be your recommendation here? I seem to recall a comment you made in some PR a while back about switching away from using console.error / console.warn. There's also this PR where we introduced a separate production-level logger, but it seems like this log message would continue to surface in Sentry which we might not want.

Copy link
Member

@Gudahtt Gudahtt Dec 20, 2024

Choose a reason for hiding this comment

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

The pattern in the linked PR seems ideal to me for non-debug logging because the client can choose whether it's enabled or not. That was generally the goal: let the client control logging, don't make it mandatory.

Logs can definitely be useful as Sentry breadcrumbs.

Copy link
Member

Choose a reason for hiding this comment

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

About this specific scenario, can we make this situation impossible? I don't quite follow how it could happen.

Is there an active poll on a deleted network that we haven't shut down, or is something else trying to get estimates from a non-existent network? I'd think the root problem lies elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I guess you're right. Maybe hiding the error isn't such a good thing in this case.

@mcmire mcmire closed this Dec 20, 2024
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.

2 participants