Skip to content

Conversation

@montelaidev
Copy link
Contributor

@montelaidev montelaidev commented Jan 8, 2026

This PR adds new hardware errors and error codes to the @metamask/keyring-utils.

See: https://consensyssoftware.atlassian.net/browse/MUL-1304?atlOrigin=eyJpIjoiZmYwZmRmNDg1NDkzNDMxMjg2ZTBmNmUwYzQzZTA2ZjgiLCJwIjoiaiJ9

Examples


Note

Adds structured hardware error handling and mappings.

  • Introduces ErrorCode, Severity, and Category enums for standardized hardware errors
  • Adds HARDWARE_ERROR_MAPPINGS for Ledger (0x codes → internal ErrorCode, Severity, Category, userMessage)
  • Implements HardwareWalletError with id, timestamp, metadata, cause, isCritical(), isWarning(), withMetadata(), toJSON(), toString(), and toDetailedString()
  • Comprehensive tests for mappings and error class behavior
  • Exposes new enums, mappings, and class via index.ts

Written by Cursor Bugbot for commit ce66cea. This will update automatically on new commits. Configure here.

@montelaidev montelaidev self-assigned this Jan 8, 2026
@montelaidev montelaidev requested a review from a team as a code owner January 8, 2026 05:07
@montelaidev montelaidev enabled auto-merge January 8, 2026 10:17
ConnTimeout = 4002,
ConnBlocked = 4003,
ConnIframeMissing = 4010,
ConnSuiteMissing = 4011,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be a "new" sub-category? 🤔 4020 instead of 4011?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its kind of the trezor iframe suite

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use just use one instead and call it ConnBridgeMissing? Or maybe even ConnTransportBridgeMissing? (I also thought of "Gateway" but "Bridge" is the term we use for this purpose.

WDYT?

ConnTimeout = 4002,
ConnBlocked = 4003,
ConnIframeMissing = 4010,
ConnSuiteMissing = 4011,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use just use one instead and call it ConnBridgeMissing? Or maybe even ConnTransportBridgeMissing? (I also thought of "Gateway" but "Bridge" is the term we use for this purpose.

WDYT?

Comment on lines 267 to 278
originalName: 'Failure_UnknownCode',
},
Init_IframeBlocked: {
customCode: ErrorCode.ConnBlocked,
message: 'Iframe blocked',
severity: Severity.Err,
category: Category.Connection,
retryStrategy: RetryStrategy.NoRetry,
userActionable: true,
userMessage:
'Connection blocked. Please check your browser settings and allow iframes.',
sdkMessage: 'Iframe blocked',
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the difference between originalName and sdkMessage here? 🤔

Also, we should re-use the constants from Trezor when possible, so 'Iframe blocked' should be Init_IframeBlocked (like the key being using the object here)

Co-authored-by: Charly Chevalier <charly.chevalier@consensys.net>
(mapping) => mapping.customCode,
);
expect(ledgerCustomCodes.length).toBeGreaterThan(0);
});
Copy link

Choose a reason for hiding this comment

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

Test claims uniqueness validation but doesn't verify it

Low Severity

The test named "should have unique error codes within each vendor" only asserts that ledgerCustomCodes.length is greater than zero. It doesn't actually verify uniqueness - that would require comparing the array length against a Set of the same values. Looking at the actual error mappings, multiple vendor codes intentionally map to the same customCode (e.g., both 0x6985 and 0x5501 map to UserRejected). The test name is misleading and could give false confidence that uniqueness is being validated when it's not.

Fix in Cursor Fix in Web

Comment on lines +4 to +7
export const HARDWARE_ERROR_MAPPINGS = {
ledger: {
vendorName: 'Ledger',
errorMappings: {
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: Maybe we could just use LEDGER_ERROR_MAPPING for this one?

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.

3 participants