Skip to content

fix: handle Trazor reject error handling.#576

Merged
dawnseeker8 merged 8 commits into
mainfrom
fix/41184-trezor-reject-error-message
Jul 2, 2026
Merged

fix: handle Trazor reject error handling.#576
dawnseeker8 merged 8 commits into
mainfrom
fix/41184-trezor-reject-error-message

Conversation

@dawnseeker8

@dawnseeker8 dawnseeker8 commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

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

  • Added new shared helpers (isUserRejectionLikeError, resolveUserRejectionErrorCode) in hw-wallet-sdk to consistently detect and classify user cancellation/rejection errors across hardware wallet libraries. [1]], [2]], [3]], [4]])
  • Updated Trezor error handling to use these helpers, mapping user cancellations and rejections to UserCancelled/UserRejected error codes instead of the generic Unknown code. [1]], [2]], [3]], [4]], [5]], [6]])

Error Handling and Propagation

  • Introduced createErrorFromTrezorResponse to 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

  • Added and expanded tests for user rejection detection, Trezor error mapping, and error propagation to verify that user cancellation and rejection errors are surfaced with the correct error codes and messages. [1]], [2]], [3]], [4]], [5]])

Changelog Updates

  • Updated CHANGELOG.md files in both hw-wallet-sdk and keyring-eth-trezor to 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-sdk 0.9.0 adds shared isUserRejectionLikeError and resolveUserRejectionErrorCode helpers (exported from user-rejection.ts) so hardware libraries can recognize cancellation/rejection across messages, Trezor codes, provider 4001, and nested cause/originalError, while not treating ConnectionClosed as user rejection.

Trezor keyring wires this in via createErrorFromTrezorResponse for failed Connect payloads (preserving payload code), refactors handleTrezorTransportError around convertToHardwareWalletError, and maps user-dismiss flows to UserCancelled / UserRejected with Trezor-specific user messages instead of Unknown. Unlock, transaction, personal message, and typed-data failure paths now throw through that helper.

Ledger bridge and other packages only bump hw-wallet-sdk to ^0.9.0; Trezor tests switch from import * as sinon to 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.

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.
@dawnseeker8 dawnseeker8 changed the title feat(hw-wallet-sdk): add user-rejection detection helpers fix: handle Trazor reject error handling. Jun 24, 2026
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.
@dawnseeker8 dawnseeker8 marked this pull request as ready for review June 25, 2026 05:59
@dawnseeker8 dawnseeker8 requested a review from a team as a code owner June 25, 2026 05:59

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 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".

Comment thread packages/keyring-eth-trezor/src/trezor-error-handler.ts
Comment thread packages/hw-wallet-sdk/src/user-rejection.ts Outdated
@dawnseeker8

Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-preview

@github-actions

Copy link
Copy Markdown

Preview builds have been published. See these instructions (from the core monorepo) for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/account-api": "1.0.4-30b0aa8",
  "@metamask-previews/hw-wallet-sdk": "0.8.0-30b0aa8",
  "@metamask-previews/keyring-api": "23.3.0-30b0aa8",
  "@metamask-previews/eth-hd-keyring": "14.1.1-30b0aa8",
  "@metamask-previews/eth-ledger-bridge-keyring": "12.2.0-30b0aa8",
  "@metamask-previews/eth-money-keyring": "3.0.0-30b0aa8",
  "@metamask-previews/eth-qr-keyring": "2.1.0-30b0aa8",
  "@metamask-previews/eth-simple-keyring": "12.0.2-30b0aa8",
  "@metamask-previews/eth-trezor-keyring": "10.1.0-30b0aa8",
  "@metamask-previews/keyring-internal-api": "11.0.1-30b0aa8",
  "@metamask-previews/keyring-internal-snap-client": "10.0.3-30b0aa8",
  "@metamask-previews/keyring-sdk": "2.2.0-30b0aa8",
  "@metamask-previews/eth-snap-keyring": "22.3.0-30b0aa8",
  "@metamask-previews/keyring-snap-client": "9.0.2-30b0aa8",
  "@metamask-previews/keyring-snap-sdk": "9.0.2-30b0aa8",
  "@metamask-previews/keyring-utils": "3.3.1-30b0aa8"
}

…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.
@dawnseeker8

Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-preview

@github-actions

Copy link
Copy Markdown

Preview builds have been published. See these instructions (from the core monorepo) for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/account-api": "1.0.4-e51c895",
  "@metamask-previews/hw-wallet-sdk": "0.9.0-e51c895",
  "@metamask-previews/keyring-api": "23.3.0-e51c895",
  "@metamask-previews/eth-hd-keyring": "14.1.1-e51c895",
  "@metamask-previews/eth-ledger-bridge-keyring": "12.2.0-e51c895",
  "@metamask-previews/eth-money-keyring": "3.0.0-e51c895",
  "@metamask-previews/eth-qr-keyring": "2.1.0-e51c895",
  "@metamask-previews/eth-simple-keyring": "12.0.2-e51c895",
  "@metamask-previews/eth-trezor-keyring": "10.1.0-e51c895",
  "@metamask-previews/keyring-internal-api": "11.0.1-e51c895",
  "@metamask-previews/keyring-internal-snap-client": "10.0.3-e51c895",
  "@metamask-previews/keyring-sdk": "2.2.0-e51c895",
  "@metamask-previews/eth-snap-keyring": "22.3.0-e51c895",
  "@metamask-previews/keyring-snap-client": "9.0.2-e51c895",
  "@metamask-previews/keyring-snap-sdk": "9.0.2-e51c895",
  "@metamask-previews/keyring-utils": "3.3.1-e51c895"
}

Comment thread packages/keyring-eth-trezor/src/trezor-keyring.test.ts
Comment thread packages/keyring-eth-trezor/src/trezor-bridge-error.ts
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.
@dawnseeker8 dawnseeker8 requested a review from montelaidev June 26, 2026 09:46
montelaidev
montelaidev previously approved these changes Jul 2, 2026
@dawnseeker8 dawnseeker8 enabled auto-merge July 2, 2026 10:55
@dawnseeker8

Copy link
Copy Markdown
Contributor Author

@copilot resolve the merge conflicts in this pull request

auto-merge was automatically disabled July 2, 2026 10:58

Head branch was pushed to by a user without write access

Copilot AI commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Done — merged main into this branch in commit chore: merge main into fix/41184-trezor-reject-error-message. Conflicts resolved:

  • keyring-eth-ledger-bridge/CHANGELOG.md: kept both Unreleased entries (hw-wallet-sdk bump from this PR + keyring-api bump from main)
  • keyring-eth-ledger-bridge/package.json and keyring-eth-trezor/package.json: kept hw-wallet-sdk@^0.9.0 (this PR) and keyring-api@^23.4.0 (main)
  • yarn.lock: resolved automatically via yarn install --no-immutable

montelaidev
montelaidev previously approved these changes Jul 2, 2026
@dawnseeker8 dawnseeker8 added this pull request to the merge queue Jul 2, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Jul 2, 2026
@dawnseeker8

Copy link
Copy Markdown
Contributor Author

@copilot resolve the merge conflicts in this pull request

Copilot AI commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Done — merged the latest main (commit 6d2e7d2) into this branch. The only conflict was hw-wallet-sdk/CHANGELOG.md; resolved by keeping both [Unreleased] sections (### Added from main and ### Fixed from this PR).

@dawnseeker8 dawnseeker8 added this pull request to the merge queue Jul 2, 2026
Merged via the queue into main with commit d7e57cb Jul 2, 2026
40 checks passed
@dawnseeker8 dawnseeker8 deleted the fix/41184-trezor-reject-error-message branch July 2, 2026 12:42
dawnseeker8 added a commit that referenced this pull request Jul 6, 2026
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>
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.

[Bug]: [Trezor] Uninformative UI error is shown in MM when the user rejects the trx signing on Trezor

3 participants