fix: handle Trazor reject error handling.#576
Conversation
Introduced shared user-rejection detection helpers in the hw-wallet-sdk to enable consistent classification of cancellation-like errors across hardware wallet libraries. This includes the addition of the `isUserRejectionLikeError` and `resolveUserRejectionErrorCode` functions, along with corresponding tests to ensure accurate functionality. Updated the changelog to reflect these changes.
Updated the Trezor keyring to surface user cancellation and rejection errors as `UserCancelled`/`UserRejected`, enhancing clarity over previous `ErrorCode.Unknown` messages. This change addresses user experience issues by providing more informative error feedback. The changelog has been updated to reflect this fix, which complements previous work in MetaMask/core and resolves related issues in the MetaMask extension.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 30b0aa8342
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions (from the Expand for full list of packages and versions. |
…n error handling Updated the @metamask/hw-wallet-sdk to version 0.9.0, which includes improved handling of user-rejection errors. The changelog has been updated to reflect these changes, ensuring better clarity in error classification. Additionally, dependencies in related packages have been updated to align with the new version.
Updated the changelog to reflect the bump of `@metamask/hw-wallet-sdk` from `^0.8.0` to `^0.9.0`, ensuring accurate documentation of changes in the project.
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions (from the Expand for full list of packages and versions. |
Refactored the error handling in the Trezor keyring to return typed HardwareWalletError instances for various error scenarios. Improved tests to validate the mapping of cancellation and unknown errors, ensuring clearer feedback for users. This change aligns with recent updates in the hw-wallet-sdk and enhances overall error classification.
Updated test files for the Trezor keyring and OneKey keyring to streamline sinon imports by replacing `import * as sinon` with specific imports for `restore`, `assert`, and `stub`. This change enhances code clarity and maintains consistency across test files. Additionally, removed unused eslint suppressions related to `import-x/namespace` from the eslint-suppressions.json file.
|
@copilot resolve the merge conflicts in this pull request |
Head branch was pushed to by a user without write access
Done — merged
|
|
@copilot resolve the merge conflicts in this pull request |
Done — merged the latest |
The changelog check failed because keyring-eth-ledger-bridge and keyring-eth-trezor both bump the @metamask/hw-wallet-sdk runtime dependency from ^0.9.0 to ^0.10.0 in this release, but their CHANGELOG.md entries only referenced the prior bump (PR #576) and not this PR. Co-authored-by: Cursor <cursoragent@cursor.com>
This pull request improves how Trezor hardware wallet errors are handled and classified, especially regarding user cancellation and rejection events. It introduces shared helpers for consistent user-rejection detection across hardware wallet libraries, updates Trezor error handling to surface these as specific error codes (
UserCancelled/UserRejected), and adds comprehensive tests to ensure correct behavior. This results in more informative error messages and better interoperability with MetaMask core and extension error handling.User Rejection Detection and Classification
isUserRejectionLikeError,resolveUserRejectionErrorCode) inhw-wallet-sdkto consistently detect and classify user cancellation/rejection errors across hardware wallet libraries. [1]], [2]], [3]], [4]])UserCancelled/UserRejectederror codes instead of the genericUnknowncode. [1]], [2]], [3]], [4]], [5]], [6]])Error Handling and Propagation
createErrorFromTrezorResponseto extract and preserve Trezor error codes from response payloads, ensuring machine-readable error codes are available for downstream mapping. Updated all Trezor keyring error throws to use this helper. [1]], [2]], [3]], [4]], [5]], [6]])Testing Improvements
Changelog Updates
CHANGELOG.mdfiles in bothhw-wallet-sdkandkeyring-eth-trezorto document these fixes and improvements. [1]], [2]])These changes ensure that when a user cancels a signing request on their Trezor device, the error is clearly and consistently reported as a user action, improving both developer and user experience.
Fixes MetaMask/metamask-extension#41184
Examples
Note
Medium Risk
Changes affect Trezor signing error classification across unlock and all sign paths; misclassification could still surface wrong UX, but behavior is heavily tested and scoped to rejection detection rather than crypto logic.
Overview
@metamask/hw-wallet-sdk0.9.0 adds sharedisUserRejectionLikeErrorandresolveUserRejectionErrorCodehelpers (exported fromuser-rejection.ts) so hardware libraries can recognize cancellation/rejection across messages, Trezor codes, provider4001, and nestedcause/originalError, while not treatingConnectionClosedas user rejection.Trezor keyring wires this in via
createErrorFromTrezorResponsefor failed Connect payloads (preserving payloadcode), refactorshandleTrezorTransportErroraroundconvertToHardwareWalletError, and maps user-dismiss flows toUserCancelled/UserRejectedwith Trezor-specific user messages instead ofUnknown. Unlock, transaction, personal message, and typed-data failure paths now throw through that helper.Ledger bridge and other packages only bump
hw-wallet-sdkto^0.9.0; Trezor tests switch fromimport * as sinonto named imports (eslint suppressions trimmed).Reviewed by Cursor Bugbot for commit feb064e. Bugbot is set up for automated code reviews on this repo. Configure here.