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

chore: Improve error handling related to keyring metadata #5316

Merged
merged 1 commit into from
Feb 13, 2025

Conversation

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Feb 12, 2025

Explanation

This is a suggestion on how to improve error handling for keyring metadata in the PR #5112. See #5112 for more details.

References

Related discussion thread: https://github.com/MetaMask/core/pull/5112/files#r1946679193

Changelog

N/A

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

This is a suggestion on how to improve error handling for keyring metadata in
the PR #5112.
// If metadata is missing, assume the data is from an installation before
// we had keyring metadata.
if (this.#keyringsMetadata.length < this.#keyrings.length) {
console.log(`Adding missing metadata for '${type}' keyring`);
Copy link
Member Author

Choose a reason for hiding this comment

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

Typically we avoid using console.log in libraries, instead preferring to pass a LogLevel logger into the constructor. This makes it easier for the client to control logging, to disable it if appropriate. You can see an example of this in the NetworkController:

That seems like the nicer way to accomplish this.

But the idea here was that the console log could provide a hint if something unexpected happens. A standard troubleshooting step is to ask for console logs from users. They show up in Sentry breadcrumbs as well.

this.#keyrings.push(keyring);
this.#keyringsMetadata.push(getDefaultKeyringMetadata());
if (this.#keyrings.length !== this.#keyringsMetadata.length) {
throw new Error('Keyring metadata missing');
Copy link
Member Author

Choose a reason for hiding this comment

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

This would tell us something has gone catastrophically wrong. This error case is the main benefit I see from this suggestion.

@PatrykLucka PatrykLucka merged commit f671b62 into multi-srp-mvp Feb 13, 2025
108 of 125 checks passed
@PatrykLucka PatrykLucka deleted the improved-keyring-metadata-error-handling branch February 13, 2025 12:57
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