Skip to content

fix: properly surface Treezor user rejection errors#8490

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

fix: properly surface Treezor user rejection errors#8490
Olivier-BB wants to merge 7 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

@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

@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 6fae189. Configure here.

this.#hasUserRejectedMessage(
error as Error & { cause?: unknown; originalError?: unknown },
visited,
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Error cause/originalError never checked for Error instances

High Severity

In #hasUserRejectedMessage, the instanceof Error branch recurses with error as Error & { cause?: unknown; originalError?: unknown } — but that type assertion is compile-time only, so it passes the same object reference back. Since error was already added to visited, the recursive call immediately returns false, meaning cause and originalError are never inspected for Error instances. The typeof error === 'object' branch below correctly checks those properties, but it's unreachable for Errors. Compare with #isSigningUserRejectedError in KeyringController.ts which correctly accesses each property individually.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 6fae189. Configure here.

@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

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