Skip to content

fix: properly surface Treezor user rejection errors#8490

Open
Olivier-BB wants to merge 11 commits into
mainfrom
fix/41184-uninformative-error-trezor
Open

fix: properly surface Treezor user rejection errors#8490
Olivier-BB wants to merge 11 commits into
mainfrom
fix/41184-uninformative-error-trezor

Conversation

@Olivier-BB

@Olivier-BB Olivier-BB commented Apr 16, 2026

Copy link
Copy Markdown

Explanation

Treezor user rejection errors were not being surfaced clearly, which could result in uninformative error handling around rejected requests.

This change updates the relevant controller flows so Treezor user rejection errors are surfaced properly, and adds test coverage in both keyring-controller and transaction-controller to verify the behavior.

KeyringController now catches signMessage/signPersonalMessage/signTransaction errors (and conditionally signTypedMessage) and normalizes cancellation-like errors by recursively inspecting code, message, stack, cause, and originalError. TransactionController similarly detects cancellation-like errors (including a Trezor/"unknown error" string case), persists them as userRejectedRequest, and updates tests to assert the persisted error code.

The TransactionController tests for "cancelled"/"canceled" signing error normalization have been updated to use the KeyringController:signTransaction messenger action handler (rather than the legacy sign option) to properly exercise the error path, reflecting the current signing architecture.

References

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
Changes error shapes thrown from core signing and transaction-failure paths; consumers that matched on raw hardware error text or KeyringControllerError wrapping may see different errors, though behavior for genuine user rejections is more correct.

Overview
Hardware wallets (e.g. Trezor) often surface user cancellations as vague strings or wrapped errors instead of EIP-1193 userRejectedRequest (4001). This PR aligns signing and transaction failure paths so UIs and downstream code can treat rejections consistently.

KeyringController adds @metamask/rpc-errors and wraps signMessage, signPersonalMessage, signTransaction, and (when applicable) signTypedMessage so cancellation-like failures become providerErrors.userRejectedRequest with the standard MetaMask denial message, preserving optional data when present. Detection recurses through code, message, stack, cause, and originalError, including 4001, cancel/canceled strings, and failure_actioncancelled.

TransactionController adds parallel #hasUserRejectedMessage logic (including a Trezor “unknown error” string heuristic) and, in #failTransaction, persists and publishes the normalized rejection error on failed txs and transactionFailed events instead of opaque hardware errors.

Changelogs and broad test coverage document the new behavior; transaction signing tests mock KeyringController:signTransaction to exercise the path.

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

@Olivier-BB Olivier-BB requested review from a team as code owners April 16, 2026 14:05
@Olivier-BB Olivier-BB added this to Bugs Apr 16, 2026
@Olivier-BB Olivier-BB removed this from Bugs Apr 16, 2026
Comment thread packages/transaction-controller/src/TransactionController.ts
@dawnseeker8

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Copilot AI and others added 2 commits May 7, 2026 08:35
…ve-error-trezor

# Conflicts:
#	packages/keyring-controller/package.json
#	packages/transaction-controller/src/TransactionController.ts

Co-authored-by: dawnseeker8 <7315988+dawnseeker8@users.noreply.github.com>
Agent-Logs-Url: https://github.com/MetaMask/core/sessions/64a5b953-7f1d-4e47-be62-0f18a2f761f9

Co-authored-by: dawnseeker8 <7315988+dawnseeker8@users.noreply.github.com>

Copilot AI commented May 7, 2026

Copy link
Copy Markdown

@copilot resolve the merge conflicts in this pull request

Resolved the merge conflicts in commit 1ef80fe. Two conflicts needed manual resolution:

  1. keyring-controller/package.json: Combined the updated dependency versions from main with our added @metamask/rpc-errors dependency.
  2. transaction-controller/TransactionController.ts: Kept our errorToPersist user-rejection normalization while incorporating the new receiptRevert logic added in main.

The yarn.lock was updated accordingly, and all 1,400+ tests across both affected packages continue to pass.

Copilot AI requested a review from dawnseeker8 May 7, 2026 08:43
@owencraston

Copy link
Copy Markdown
Contributor

@Olivier-BB please update this branch and fix CI so we can get this reviewed and merged.

@dawnseeker8

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

dawnseeker8 and others added 4 commits June 14, 2026 16:25
…essage methods

- Introduced tests to ensure that errors with code 4001 and string rejections are normalized to user rejection errors.
- Added checks to verify that non-rejection errors are re-thrown unchanged, including those with circular references.
- Included a test for normalizing cancellation-like errors in signPersonalMessage to a 4001 code.
- Consolidated multiple lines of jest.spyOn calls into single lines for improved readability.
- Maintained existing test functionality while enhancing code clarity.
Document the user-rejection error normalization changes in
keyring-controller and transaction-controller, satisfying the
changelog check for PR #8490.

Co-authored-by: Cursor <cursoragent@cursor.com>
@dawnseeker8

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

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

4 participants