Skip to content

feat(snap-account-service): report migration error - #9696

Merged
ccharly merged 12 commits into
mainfrom
cc/feat/snap-keyring-v2-migration-error-reporting
Jul 30, 2026
Merged

feat(snap-account-service): report migration error#9696
ccharly merged 12 commits into
mainfrom
cc/feat/snap-keyring-v2-migration-error-reporting

Conversation

@ccharly

@ccharly ccharly commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Explanation

Right now, we only console.log if the migration fails (which is not supposed to happen). We have seen some user reports (with the console log Migration failed during unlock), though, it's hard to assess what's the underlying error of this failure.

We now want to instrument each steps and report those error properly so we can (hopefully) have a better understanding of what's the real failure.

References

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 communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Medium Risk
Touches mandatory unlock-time keyring migration and error reporting; behavior on failure is clearer but migration logic itself is unchanged aside from error wrapping.

Overview
Snap keyring v2 migration failures are now reported to Sentry instead of only logging to the console, with messages sanitized so addresses and other sensitive data are not sent upstream.

A new errors module introduces SafeError, withSafeError, and reportError. Migration steps (addNewKeyring, removeKeyring, and the overall unlock-time migration) run inside withSafeError, which keeps KeyringControllerError and existing SafeErrors as-is, turns superstruct StructErrors into path/type-only summaries, and replaces other errors with generic step-labeled messages. On unlock failure, reportError logs and calls the messenger’s optional captureException with a wrapper error whose cause is the (sanitized) failure.

Tests cover sanitization behavior, Sentry wiring, and migration error paths; the changelog documents the addition. SnapTracker gains a small test that removal events for untracked Snaps are ignored.

Reviewed by Cursor Bugbot for commit a1d0bbf. Bugbot is set up for automated code reviews on this repo. Configure here.

@ccharly
ccharly marked this pull request as ready for review July 29, 2026 16:26
@ccharly
ccharly requested review from a team as code owners July 29, 2026 16:26
@ccharly
ccharly temporarily deployed to default-branch July 29, 2026 16:26 — with GitHub Actions Inactive
});
},
(error) => {
reportError(this.#messenger, 'Migration failed after unlock', error);

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.

No real sensitive data (from error) should escape from here. I ran multiple checks with claude on this.

This can be compared with living an error bubbles up from a :withKeyring* call basically, which means, errors from keyring.{serialize,deserialize} could be thrown here.

In this context, we mostly use Snap keyrings (legacy + Snap keyring v2), so we could expect errors coming from there.

The real errors we don't have much control over are superstruct errors. We now wrap sensitive fields with our new decorator (superstruct.sensitive), but it's not widely used yet.

The other alternative is to wrap each steps of the migration with various try { ... } catch { throw Error('This step failed with ${text}'); }, but that would make any analysis still pretty difficult I guess...

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.

Ok, finally introduce a new pattern where we only report errors we know are "safe" to be reported.

It's not perfect, but I prefer this solution for now. Once we know why the migration is failing, we'll fix and eventually, remove those SafeErrors.

Though, I think the pattern is elegant enough that we could use it in place where we need it.

On a side note, we should over-abuse our new superstruct.sensitive too to avoid letting dynamic value escape through superstruct validation IMO. But for now, it's not widespread enough.

Comment thread packages/snap-account-service/src/errors.ts

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit cc380a1. Configure here.

Comment thread packages/snap-account-service/src/errors.ts
@ccharly

ccharly commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-preview

@github-actions

Copy link
Copy Markdown
Contributor

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/account-tree-controller@7.5.5-preview-6c92d881a
@metamask-previews/accounts-controller@39.0.5-preview-6c92d881a
@metamask-previews/address-book-controller@7.1.2-preview-6c92d881a
@metamask-previews/ai-controllers@0.8.0-preview-6c92d881a
@metamask-previews/analytics-controller@1.2.1-preview-6c92d881a
@metamask-previews/analytics-data-regulation-controller@0.0.0-preview-6c92d881a
@metamask-previews/announcement-controller@8.1.0-preview-6c92d881a
@metamask-previews/app-metadata-controller@2.0.1-preview-6c92d881a
@metamask-previews/approval-controller@9.0.2-preview-6c92d881a
@metamask-previews/assets-controller@11.3.0-preview-6c92d881a
@metamask-previews/assets-controllers@110.0.1-preview-6c92d881a
@metamask-previews/authenticated-user-storage@3.0.1-preview-6c92d881a
@metamask-previews/base-controller@9.1.0-preview-6c92d881a
@metamask-previews/base-data-service@0.1.3-preview-6c92d881a
@metamask-previews/bitcoin-regtest-up@1.0.0-preview-6c92d881a
@metamask-previews/bridge-controller@78.0.1-preview-6c92d881a
@metamask-previews/bridge-status-controller@74.6.0-preview-6c92d881a
@metamask-previews/build-utils@3.0.4-preview-6c92d881a
@metamask-previews/chain-agnostic-permission@1.7.0-preview-6c92d881a
@metamask-previews/chomp-api-service@4.0.0-preview-6c92d881a
@metamask-previews/claims-controller@0.5.3-preview-6c92d881a
@metamask-previews/client-controller@1.0.1-preview-6c92d881a
@metamask-previews/client-utils@1.3.1-preview-6c92d881a
@metamask-previews/compliance-controller@2.1.0-preview-6c92d881a
@metamask-previews/composable-controller@12.0.1-preview-6c92d881a
@metamask-previews/config-registry-controller@0.4.1-preview-6c92d881a
@metamask-previews/connectivity-controller@0.3.0-preview-6c92d881a
@metamask-previews/controller-utils@12.3.0-preview-6c92d881a
@metamask-previews/core-backend@8.0.0-preview-6c92d881a
@metamask-previews/delegation-controller@3.0.2-preview-6c92d881a
@metamask-previews/earn-controller@12.2.2-preview-6c92d881a
@metamask-previews/eip-5792-middleware@3.0.5-preview-6c92d881a
@metamask-previews/eip-7702-internal-rpc-middleware@0.1.1-preview-6c92d881a
@metamask-previews/eip1193-permission-middleware@2.0.1-preview-6c92d881a
@metamask-previews/ens-controller@19.1.5-preview-6c92d881a
@metamask-previews/eth-block-tracker@15.0.1-preview-6c92d881a
@metamask-previews/eth-json-rpc-middleware@23.1.3-preview-6c92d881a
@metamask-previews/eth-json-rpc-provider@6.0.1-preview-6c92d881a
@metamask-previews/foundryup@1.0.1-preview-6c92d881a
@metamask-previews/gas-fee-controller@26.3.0-preview-6c92d881a
@metamask-previews/gator-permissions-controller@4.2.3-preview-6c92d881a
@metamask-previews/geolocation-controller@0.1.3-preview-6c92d881a
@metamask-previews/java-tron-up@1.0.0-preview-6c92d881a
@metamask-previews/json-rpc-engine@10.5.0-preview-6c92d881a
@metamask-previews/json-rpc-middleware-stream@8.0.8-preview-6c92d881a
@metamask-previews/keyring-controller@27.1.0-preview-6c92d881a
@metamask-previews/local-node-utils@1.0.0-preview-6c92d881a
@metamask-previews/logging-controller@8.0.2-preview-6c92d881a
@metamask-previews/message-manager@14.1.2-preview-6c92d881a
@metamask-previews/messenger@2.0.0-preview-6c92d881a
@metamask-previews/messenger-cli@0.2.0-preview-6c92d881a
@metamask-previews/money-account-api-data-service@0.4.0-preview-6c92d881a
@metamask-previews/money-account-balance-service@2.3.0-preview-6c92d881a
@metamask-previews/money-account-controller@0.3.3-preview-6c92d881a
@metamask-previews/money-account-upgrade-controller@3.0.0-preview-6c92d881a
@metamask-previews/multichain-account-service@13.0.0-preview-6c92d881a
@metamask-previews/multichain-api-middleware@4.0.1-preview-6c92d881a
@metamask-previews/multichain-network-controller@3.2.1-preview-6c92d881a
@metamask-previews/multichain-transactions-controller@7.1.1-preview-6c92d881a
@metamask-previews/name-controller@9.1.2-preview-6c92d881a
@metamask-previews/network-connection-banner-controller@0.1.0-preview-6c92d881a
@metamask-previews/network-controller@34.0.0-preview-6c92d881a
@metamask-previews/network-enablement-controller@5.6.0-preview-6c92d881a
@metamask-previews/notification-services-controller@26.0.0-preview-6c92d881a
@metamask-previews/passkey-controller@3.0.0-preview-6c92d881a
@metamask-previews/permission-controller@13.1.1-preview-6c92d881a
@metamask-previews/permission-log-controller@5.1.0-preview-6c92d881a
@metamask-previews/perps-controller@10.0.0-preview-6c92d881a
@metamask-previews/phishing-controller@17.3.0-preview-6c92d881a
@metamask-previews/platform-api-docs@0.0.0-preview-6c92d881a
@metamask-previews/polling-controller@16.0.8-preview-6c92d881a
@metamask-previews/preferences-controller@23.1.0-preview-6c92d881a
@metamask-previews/profile-metrics-controller@4.0.2-preview-6c92d881a
@metamask-previews/profile-sync-controller@28.3.0-preview-6c92d881a
@metamask-previews/ramps-controller@18.0.0-preview-6c92d881a
@metamask-previews/rate-limit-controller@7.0.1-preview-6c92d881a
@metamask-previews/react-data-query@0.2.2-preview-6c92d881a
@metamask-previews/remote-feature-flag-controller@4.2.2-preview-6c92d881a
@metamask-previews/sample-controllers@5.0.3-preview-6c92d881a
@metamask-previews/seedless-onboarding-controller@10.1.0-preview-6c92d881a
@metamask-previews/selected-network-controller@26.1.5-preview-6c92d881a
@metamask-previews/sentinel-api-service@1.0.0-preview-6c92d881a
@metamask-previews/shield-controller@5.1.3-preview-6c92d881a
@metamask-previews/signature-controller@39.2.7-preview-6c92d881a
@metamask-previews/smart-transactions-controller@25.0.1-preview-6c92d881a
@metamask-previews/snap-account-service@2.0.0-preview-6c92d881a
@metamask-previews/social-controllers@2.7.0-preview-6c92d881a
@metamask-previews/solana-test-validator-up@1.0.0-preview-6c92d881a
@metamask-previews/stellar-quickstart-up@0.0.0-preview-6c92d881a
@metamask-previews/storage-service@1.0.2-preview-6c92d881a
@metamask-previews/subscription-controller@6.2.1-preview-6c92d881a
@metamask-previews/transaction-controller@69.3.0-preview-6c92d881a
@metamask-previews/transaction-pay-controller@26.0.1-preview-6c92d881a
@metamask-previews/user-operation-controller@41.2.7-preview-6c92d881a
@metamask-previews/wallet@8.1.0-preview-6c92d881a
@metamask-previews/wallet-cli@0.0.0-preview-6c92d881a

Comment thread packages/snap-account-service/CHANGELOG.md Outdated
Comment thread packages/snap-account-service/src/errors.ts Outdated
Comment thread packages/snap-account-service/CHANGELOG.md Outdated
ccharly and others added 3 commits July 30, 2026 15:09
Co-authored-by: Mathieu Artu <mathieu.artu@consensys.net>
@ccharly

ccharly commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-preview

@github-actions

Copy link
Copy Markdown
Contributor

Preview builds have been published. Learn how to use preview builds in other projects.

Expand for full list of packages and versions.
@metamask-previews/account-tree-controller@7.5.5-preview-a1d0bbfa8
@metamask-previews/accounts-controller@39.0.5-preview-a1d0bbfa8
@metamask-previews/address-book-controller@7.1.2-preview-a1d0bbfa8
@metamask-previews/ai-controllers@0.8.0-preview-a1d0bbfa8
@metamask-previews/analytics-controller@1.2.1-preview-a1d0bbfa8
@metamask-previews/analytics-data-regulation-controller@0.0.0-preview-a1d0bbfa8
@metamask-previews/announcement-controller@8.1.0-preview-a1d0bbfa8
@metamask-previews/app-metadata-controller@2.0.1-preview-a1d0bbfa8
@metamask-previews/approval-controller@9.0.2-preview-a1d0bbfa8
@metamask-previews/assets-controller@11.3.0-preview-a1d0bbfa8
@metamask-previews/assets-controllers@110.0.1-preview-a1d0bbfa8
@metamask-previews/authenticated-user-storage@3.0.1-preview-a1d0bbfa8
@metamask-previews/base-controller@9.1.0-preview-a1d0bbfa8
@metamask-previews/base-data-service@0.1.3-preview-a1d0bbfa8
@metamask-previews/bitcoin-regtest-up@1.0.0-preview-a1d0bbfa8
@metamask-previews/bridge-controller@78.0.1-preview-a1d0bbfa8
@metamask-previews/bridge-status-controller@74.6.0-preview-a1d0bbfa8
@metamask-previews/build-utils@3.0.4-preview-a1d0bbfa8
@metamask-previews/chain-agnostic-permission@1.7.0-preview-a1d0bbfa8
@metamask-previews/chomp-api-service@4.0.0-preview-a1d0bbfa8
@metamask-previews/claims-controller@0.5.3-preview-a1d0bbfa8
@metamask-previews/client-controller@1.0.1-preview-a1d0bbfa8
@metamask-previews/client-utils@1.3.1-preview-a1d0bbfa8
@metamask-previews/compliance-controller@2.1.0-preview-a1d0bbfa8
@metamask-previews/composable-controller@12.0.1-preview-a1d0bbfa8
@metamask-previews/config-registry-controller@0.4.1-preview-a1d0bbfa8
@metamask-previews/connectivity-controller@0.3.0-preview-a1d0bbfa8
@metamask-previews/controller-utils@12.3.0-preview-a1d0bbfa8
@metamask-previews/core-backend@8.0.0-preview-a1d0bbfa8
@metamask-previews/delegation-controller@3.0.2-preview-a1d0bbfa8
@metamask-previews/earn-controller@12.2.2-preview-a1d0bbfa8
@metamask-previews/eip-5792-middleware@3.0.5-preview-a1d0bbfa8
@metamask-previews/eip-7702-internal-rpc-middleware@0.1.1-preview-a1d0bbfa8
@metamask-previews/eip1193-permission-middleware@2.0.1-preview-a1d0bbfa8
@metamask-previews/ens-controller@19.1.5-preview-a1d0bbfa8
@metamask-previews/eth-block-tracker@15.0.1-preview-a1d0bbfa8
@metamask-previews/eth-json-rpc-middleware@23.1.3-preview-a1d0bbfa8
@metamask-previews/eth-json-rpc-provider@6.0.1-preview-a1d0bbfa8
@metamask-previews/foundryup@1.0.1-preview-a1d0bbfa8
@metamask-previews/gas-fee-controller@26.3.0-preview-a1d0bbfa8
@metamask-previews/gator-permissions-controller@4.2.3-preview-a1d0bbfa8
@metamask-previews/geolocation-controller@0.1.3-preview-a1d0bbfa8
@metamask-previews/java-tron-up@1.0.0-preview-a1d0bbfa8
@metamask-previews/json-rpc-engine@10.5.0-preview-a1d0bbfa8
@metamask-previews/json-rpc-middleware-stream@8.0.8-preview-a1d0bbfa8
@metamask-previews/keyring-controller@27.1.0-preview-a1d0bbfa8
@metamask-previews/local-node-utils@1.0.0-preview-a1d0bbfa8
@metamask-previews/logging-controller@8.0.2-preview-a1d0bbfa8
@metamask-previews/message-manager@14.1.2-preview-a1d0bbfa8
@metamask-previews/messenger@2.0.0-preview-a1d0bbfa8
@metamask-previews/messenger-cli@0.2.0-preview-a1d0bbfa8
@metamask-previews/money-account-api-data-service@0.4.0-preview-a1d0bbfa8
@metamask-previews/money-account-balance-service@2.3.0-preview-a1d0bbfa8
@metamask-previews/money-account-controller@0.3.3-preview-a1d0bbfa8
@metamask-previews/money-account-upgrade-controller@3.0.0-preview-a1d0bbfa8
@metamask-previews/multichain-account-service@13.0.0-preview-a1d0bbfa8
@metamask-previews/multichain-api-middleware@4.0.1-preview-a1d0bbfa8
@metamask-previews/multichain-network-controller@3.2.1-preview-a1d0bbfa8
@metamask-previews/multichain-transactions-controller@7.1.1-preview-a1d0bbfa8
@metamask-previews/name-controller@9.1.2-preview-a1d0bbfa8
@metamask-previews/network-connection-banner-controller@0.1.0-preview-a1d0bbfa8
@metamask-previews/network-controller@34.0.0-preview-a1d0bbfa8
@metamask-previews/network-enablement-controller@5.6.0-preview-a1d0bbfa8
@metamask-previews/notification-services-controller@26.0.0-preview-a1d0bbfa8
@metamask-previews/passkey-controller@3.0.0-preview-a1d0bbfa8
@metamask-previews/permission-controller@13.1.1-preview-a1d0bbfa8
@metamask-previews/permission-log-controller@5.1.0-preview-a1d0bbfa8
@metamask-previews/perps-controller@10.0.0-preview-a1d0bbfa8
@metamask-previews/phishing-controller@17.3.0-preview-a1d0bbfa8
@metamask-previews/platform-api-docs@0.0.0-preview-a1d0bbfa8
@metamask-previews/polling-controller@16.0.8-preview-a1d0bbfa8
@metamask-previews/preferences-controller@23.1.0-preview-a1d0bbfa8
@metamask-previews/profile-metrics-controller@4.0.2-preview-a1d0bbfa8
@metamask-previews/profile-sync-controller@28.3.0-preview-a1d0bbfa8
@metamask-previews/ramps-controller@18.0.0-preview-a1d0bbfa8
@metamask-previews/rate-limit-controller@7.0.1-preview-a1d0bbfa8
@metamask-previews/react-data-query@0.2.2-preview-a1d0bbfa8
@metamask-previews/remote-feature-flag-controller@4.2.2-preview-a1d0bbfa8
@metamask-previews/sample-controllers@5.0.3-preview-a1d0bbfa8
@metamask-previews/seedless-onboarding-controller@10.1.0-preview-a1d0bbfa8
@metamask-previews/selected-network-controller@26.1.5-preview-a1d0bbfa8
@metamask-previews/sentinel-api-service@1.0.0-preview-a1d0bbfa8
@metamask-previews/shield-controller@5.1.3-preview-a1d0bbfa8
@metamask-previews/signature-controller@39.2.7-preview-a1d0bbfa8
@metamask-previews/smart-transactions-controller@25.0.1-preview-a1d0bbfa8
@metamask-previews/snap-account-service@2.0.0-preview-a1d0bbfa8
@metamask-previews/social-controllers@2.7.0-preview-a1d0bbfa8
@metamask-previews/solana-test-validator-up@1.0.0-preview-a1d0bbfa8
@metamask-previews/stellar-quickstart-up@0.0.0-preview-a1d0bbfa8
@metamask-previews/storage-service@1.0.2-preview-a1d0bbfa8
@metamask-previews/subscription-controller@6.2.1-preview-a1d0bbfa8
@metamask-previews/transaction-controller@69.3.0-preview-a1d0bbfa8
@metamask-previews/transaction-pay-controller@26.0.1-preview-a1d0bbfa8
@metamask-previews/user-operation-controller@41.2.7-preview-a1d0bbfa8
@metamask-previews/wallet@8.1.0-preview-a1d0bbfa8
@metamask-previews/wallet-cli@0.0.0-preview-a1d0bbfa8

@mathieuartu mathieuartu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Awesome!

@ccharly
ccharly added this pull request to the merge queue Jul 30, 2026
Merged via the queue into main with commit 6e1a29b Jul 30, 2026
148 checks passed
@ccharly
ccharly deleted the cc/feat/snap-keyring-v2-migration-error-reporting branch July 30, 2026 15:11
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.

3 participants