Skip to content

fix: properly surface Treezor user rejection errors#8490

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

fix: properly surface Treezor user rejection errors#8490
Olivier-BB wants to merge 10 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 the error type and message surfaced when users reject signing, which affects dapps and UI; heuristic string/code matching could theoretically mislabel non-rejection failures.

Overview
Signing flows now map hardware-wallet and other cancellation-like failures to a standard userRejectedRequest (4001) provider error instead of opaque or wrapped errors.

KeyringController adds @metamask/rpc-errors and wraps signMessage, signPersonalMessage, signTransaction, and (when applicable) signTypedMessage so rejections detected via code 4001, message/stack patterns (user rejected, cancelled/canceled, failure_actioncancelled), and nested cause/originalError become providerErrors.userRejectedRequest with a fixed MetaMask denial message (optional data preserved). Non-rejection errors are unchanged; signTypedMessage still wraps other failures in KeyringControllerError.

TransactionController adds similar heuristics (including a Trezor unknown error string case) and, on failed txs, persists and emits the normalized rejection error on transactionFailed. Tests cover both controllers and the KeyringController:signTransaction messenger path.

Reviewed by Cursor Bugbot for commit ae7c32a. 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