Skip to content

fix: error handling for Ledger hardware wallet errors#40597

Merged
david0xd merged 4 commits intomainfrom
dd/fix-hw-wallet-errors
Mar 4, 2026
Merged

fix: error handling for Ledger hardware wallet errors#40597
david0xd merged 4 commits intomainfrom
dd/fix-hw-wallet-errors

Conversation

@david0xd
Copy link
Contributor

@david0xd david0xd commented Mar 4, 2026

Description

This PR adds fix for error handling and message display for Ledger hardware wallets.

Open in GitHub Codespaces

Changelog

CHANGELOG entry: Fix error message displayed for Ledger hardware wallets

Related issues

Fixes: #39726

Manual testing steps

  1. Go to MetaMask extension account list and start process for adding hardware wallet.
  2. Choose Ledger.
  3. On Ledger, open apps that are not supported (e.g. Solana, BTC) or close all apps.
  4. Click continue and allow Ledger device to connect to the web browser.
  5. Observe error message displayed at the top of the MetaMask extension page.
  6. Make sure that there are no "UNKNOWN ERRORS".
  7. Make sure that Ethereum app is working as expected.

Screenshots/Recordings

Before

image image

After

Testing with multiple apps or when all are closed
Test device used: Ledger Flex
Browser: Chrome
Running local extension build from main

Screenshot 2026-03-04 at 13 05 28

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Low Risk
Low risk UI behavior change limited to Ledger connect error messaging; main risk is misclassification of certain errors leading to different user-facing messages.

Overview
Improves Ledger hardware-wallet connection error display by first mapping thrown errors through shared hw-wallet-sdk logic (toHardwareWalletError) and showing the SDK-provided userMessage for recognized Ledger status codes (excluding Unknown/ConnectionClosed).

Keeps the existing fallback error parsing for U2F/timeout/legacy Ledger error codes, but updates LEDGER_ERRORS_CODES messages to be localized via t.

Adds tests covering the new Ledger mapping behavior (mapped status code shows SDK message; unmapped/connection-closed cases fall back to the original error message).

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

@david0xd david0xd self-assigned this Mar 4, 2026
@david0xd david0xd added the team-accounts-framework Accounts team label Mar 4, 2026
@metamaskbot metamaskbot added the team-extension-platform Extension Platform team label Mar 4, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2026

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@github-actions github-actions bot added the size-S label Mar 4, 2026
@montelaidev
Copy link
Contributor

We should be able to use this util to create the error

export function toHardwareWalletError(
error: unknown,
walletType: HardwareWalletType,
): HardwareWalletError {
if (error instanceof HardwareWalletError) {
return error;

@metamaskbotv2
Copy link
Contributor

metamaskbotv2 bot commented Mar 4, 2026

Builds ready [c384961]
⚡ Performance Benchmarks
👆 Interaction Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Load New Accountload_new_account2902872932293293
total2902872932293293
Confirm Txconfirm_tx6086604361273261076127
total6086604361273261076127
Bridge User Actionsbridge_load_page26724827611273276
bridge_load_asset_picker18413028259221282
bridge_search_token71670173313730733
total1127110411552011351155
🔌 Startup Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Standard HomeuiStartup13871159176511814621596
load1168949144410312501329
domContentLoaded1158934143610112361319
domInteractive2716110192477
firstPaint196621317190213348
backgroundConnect19918138022201231
firstReactRender19124762031
initialActions107124
loadScripts97775712519910571135
setupStore1364061425
numNetworkReqs312290202287
Power User HomeuiStartup250214329732184921058727
load12011045168914512301548
domContentLoaded11841032167014112121517
domInteractive3519134203486
firstPaint1827840782252341
backgroundConnect878265679915433655157
firstReactRender25154982640
initialActions105112
loadScripts970829144613610061301
setupStore1674891940
numNetworkReqs73401632584127
🧭 User Journey Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Onboarding Import WalletimportWalletToSocialScreen2182162201218220
srpButtonToSrpForm92919319293
confirmSrpToPwForm21212102121
pwFormToMetricsScreen15151501515
metricsToWalletReadyScreen16151601616
doneButtonToHomeScreen60057263523604635
openAccountMenuToAccountListLoaded28062476297919029332979
total3857382338832538833883
Onboarding New WalletcreateWalletToSocialScreen2192192190219219
srpButtonToPwForm1051041081105108
createPwToRecoveryScreen888088
skipBackupToMetricsScreen35343713537
agreeButtonToOnboardingSuccess16151611616
doneButtonToAssetList52148556834552568
total91286794935938949
Asset DetailsassetClickToPriceChart47425444954
total47425444954
Solana Asset DetailsassetClickToPriceChart84808738787
total84808738787
Import Srp HomeloginToHomeScreen1996190420565820372056
openAccountMenuAfterLogin543172176972
homeAfterImportWithNewWallet29352739321819130953218
total50674713556131252775561
Send TransactionsopenSendPageFromHome32264373843
selectTokenToSendFormLoaded22182842328
reviewTransactionToConfirmationPage8508498501850850
total9058939158909915
SwapopenSwapPageFromHome1141121172115117
fetchAndDisplaySwapQuotes289828972900129002900
total301330113015130153015
🌐 Dapp Page Load Benchmarks

Current Commit: c384961 | Date: 3/4/2026

📄 Localhost MetaMask Test Dapp

Samples: 100

Summary

  • pageLoadTime-> current mean value: 1.05s (±39ms) 🟡 | historical mean value: 1.06s ⬇️ (historical data)
  • domContentLoaded-> current mean value: 738ms (±37ms) 🟢 | historical mean value: 748ms ⬇️ (historical data)
  • firstContentfulPaint-> current mean value: 81ms (±11ms) 🟢 | historical mean value: 83ms ⬇️ (historical data)

📈 Detailed Results

Metric Mean Std Dev Min Max P95 P99
pageLoadTime 1.05s 39ms 1.03s 1.34s 1.07s 1.34s
domContentLoaded 738ms 37ms 715ms 1.02s 748ms 1.02s
firstPaint 81ms 11ms 64ms 180ms 88ms 180ms
firstContentfulPaint 81ms 11ms 64ms 180ms 88ms 180ms
largestContentfulPaint 0ms 0ms 0ms 0ms 0ms 0ms
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 1.34 KiB (0.03%)
  • ui: -7.75 KiB (-0.09%)
  • common: 618 Bytes (0.01%)

@metamaskbotv2
Copy link
Contributor

metamaskbotv2 bot commented Mar 4, 2026

Builds ready [da11506]
⚡ Performance Benchmarks
👆 Interaction Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Load New Accountload_new_account30226735536332355
total30226735536332355
Confirm Txconfirm_tx6095608161081061016108
total6095608161081061016108
Bridge User Actionsbridge_load_page21019822410212224
bridge_load_asset_picker1951852057198205
bridge_search_token71370373613709736
total1154109912686311761268
🔌 Startup Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Standard HomeuiStartup14601238199610415011631
load1225102116469612701389
domContentLoaded1218101616179412661373
domInteractive3018124212588
firstPaint1537538272210263
backgroundConnect21419129916216249
firstReactRender19133742028
initialActions106124
loadScripts102181414069310711171
setupStore1363251523
numNetworkReqs312293202284
Power User HomeuiStartup17991457264116318422059
load12211083190717211991693
domContentLoaded12041070188716711871664
domInteractive42212463539110
firstPaint204801742180258413
backgroundConnect31227249827324347
firstReactRender23164852431
initialActions104113
loadScripts97584316491659521459
setupStore1684361828
numNetworkReqs60371542758140
🧭 User Journey Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Onboarding Import WalletimportWalletToSocialScreen2192182211220221
srpButtonToSrpForm97921045102104
confirmSrpToPwForm22212312223
pwFormToMetricsScreen15151601516
metricsToWalletReadyScreen16161701717
doneButtonToHomeScreen65059671050688710
openAccountMenuToAccountListLoaded2919289729441929302944
total3931387540125439784012
Onboarding New WalletcreateWalletToSocialScreen2192192190219219
srpButtonToPwForm1051021103105110
createPwToRecoveryScreen888088
skipBackupToMetricsScreen36343923739
agreeButtonToOnboardingSuccess16161601616
doneButtonToAssetList617480725100686725
total100786411089310701108
Asset DetailsassetClickToPriceChart643898279698
total643898279698
Solana Asset DetailsassetClickToPriceChart78708358383
total78708358383
Import Srp HomeloginToHomeScreen22561964257520923862575
openAccountMenuAfterLogin51445665656
homeAfterImportWithNewWallet2630253127117026772711
total49714890512010651205120
Send TransactionsopenSendPageFromHome24183672736
selectTokenToSendFormLoaded25153473234
reviewTransactionToConfirmationPage8518438597858859
total8998919138904913
SwapopenSwapPageFromHome1061021103106110
fetchAndDisplaySwapQuotes289228842902628962902
total299929903006630033006
🌐 Dapp Page Load Benchmarks

Current Commit: da11506 | Date: 3/4/2026

📄 Localhost MetaMask Test Dapp

Samples: 100

Summary

  • pageLoadTime-> current mean value: 1.05s (±59ms) 🟡 | historical mean value: 1.06s ⬇️ (historical data)
  • domContentLoaded-> current mean value: 741ms (±56ms) 🟢 | historical mean value: 748ms ⬇️ (historical data)
  • firstContentfulPaint-> current mean value: 82ms (±9ms) 🟢 | historical mean value: 82ms ⬇️ (historical data)

📈 Detailed Results

Metric Mean Std Dev Min Max P95 P99
pageLoadTime 1.05s 59ms 1.02s 1.37s 1.07s 1.37s
domContentLoaded 741ms 56ms 712ms 1.05s 761ms 1.05s
firstPaint 82ms 9ms 68ms 156ms 96ms 156ms
firstContentfulPaint 82ms 9ms 68ms 156ms 96ms 156ms
largestContentfulPaint 0ms 0ms 0ms 0ms 0ms 0ms
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 1.72 KiB (0.03%)
  • ui: -4.97 KiB (-0.06%)
  • common: 617 Bytes (0.01%)

@metamaskbotv2
Copy link
Contributor

metamaskbotv2 bot commented Mar 4, 2026

Builds ready [21eb102]
⚡ Performance Benchmarks
👆 Interaction Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Load New Accountload_new_account29426534127306341
total29426534127306341
Confirm Txconfirm_tx6068604560871460756087
total6068604560871460756087
Bridge User Actionsbridge_load_page22921225516236255
bridge_load_asset_picker20718122818217228
bridge_search_token72070474317740743
total1170112212745911981274
🔌 Startup Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Standard HomeuiStartup14291225183110714691619
load1202101314859612391387
domContentLoaded1196100714719512351379
domInteractive2916124202679
firstPaint1507141371199264
backgroundConnect21219427013216235
firstReactRender20135072133
initialActions207124
loadScripts99980312559310311182
setupStore1362541520
numNetworkReqs312290192279
Power User HomeuiStartup21721470662074122853777
load12631059206116012811666
domContentLoaded12471051203215812651625
domInteractive3922177283698
firstPaint20685537102280377
backgroundConnect47227624813943991162
firstReactRender26186272839
initialActions105113
loadScripts1021839177815210321399
setupStore1664871927
numNetworkReqs74391632683128
🧭 User Journey Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Onboarding Import WalletimportWalletToSocialScreen2192172212220221
srpButtonToSrpForm93929419394
confirmSrpToPwForm21212202222
pwFormToMetricsScreen15151501515
metricsToWalletReadyScreen16151611616
doneButtonToHomeScreen705582846117837846
openAccountMenuToAccountListLoaded26852501296522129462965
total37533538391213738923912
Onboarding New WalletcreateWalletToSocialScreen2192162222221222
srpButtonToPwForm1111031238118123
createPwToRecoveryScreen888088
skipBackupToMetricsScreen34333513435
agreeButtonToOnboardingSuccess16151601616
doneButtonToAssetList56349270980589709
total91889096830912968
Asset DetailsassetClickToPriceChart42374434444
total42374434444
Solana Asset DetailsassetClickToPriceChart71677637176
total71677637176
Import Srp HomeloginToHomeScreen2004197220512920022051
openAccountMenuAfterLogin513464105764
homeAfterImportWithNewWallet29482733318317531043183
total50644751555728751905557
Send TransactionsopenSendPageFromHome23163173031
selectTokenToSendFormLoaded21202102121
reviewTransactionToConfirmationPage8488458502848850
total8888838975889897
SwapopenSwapPageFromHome1201121349127134
fetchAndDisplaySwapQuotes289428932895128942895
total3020300530401330273040
🌐 Dapp Page Load Benchmarks

Current Commit: 21eb102 | Date: 3/4/2026

📄 Localhost MetaMask Test Dapp

Samples: 100

Summary

  • pageLoadTime-> current mean value: 1.04s (±40ms) 🟡 | historical mean value: 1.06s ⬇️ (historical data)
  • domContentLoaded-> current mean value: 730ms (±38ms) 🟢 | historical mean value: 746ms ⬇️ (historical data)
  • firstContentfulPaint-> current mean value: 80ms (±11ms) 🟢 | historical mean value: 82ms ⬇️ (historical data)

📈 Detailed Results

Metric Mean Std Dev Min Max P95 P99
pageLoadTime 1.04s 40ms 1.01s 1.34s 1.05s 1.34s
domContentLoaded 730ms 38ms 703ms 1.01s 741ms 1.01s
firstPaint 80ms 11ms 60ms 176ms 88ms 176ms
firstContentfulPaint 80ms 11ms 60ms 176ms 88ms 176ms
largestContentfulPaint 0ms 0ms 0ms 0ms 0ms 0ms
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 1.45 KiB (0.03%)
  • ui: -2.73 KiB (-0.03%)
  • common: 442 Bytes (0%)

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 4, 2026

@david0xd david0xd marked this pull request as ready for review March 4, 2026 16:15
@metamaskbotv2
Copy link
Contributor

metamaskbotv2 bot commented Mar 4, 2026

Builds ready [b646dc9]
⚡ Performance Benchmarks
👆 Interaction Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Load New Accountload_new_account29127330717307307
total29127330717307307
Confirm Txconfirm_tx6056603261163560386116
total6056603261163560386116
Bridge User Actionsbridge_load_page26024227614271276
bridge_load_asset_picker25017330556303305
bridge_search_token72371073511731735
total1248113513497813161349
🔌 Startup Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Standard HomeuiStartup14101189184011414451612
load118496815049812111363
domContentLoaded117896614959712071355
domInteractive2917102192577
firstPaint155661257133198286
backgroundConnect21219137020216238
firstReactRender19124662031
initialActions106125
loadScripts98378612909710131165
setupStore1262851521
numNetworkReqs312289192280
Power User HomeuiStartup19791333568168620602885
load11831039180215711831583
domContentLoaded11661029179515511751560
domInteractive39201992936103
firstPaint195821803178253311
backgroundConnect4282654209469342933
firstReactRender23165662432
initialActions104112
loadScripts95781015601509651328
setupStore1564161825
numNetworkReqs69371652575126
🧭 User Journey Benchmarks
BenchmarkMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P75 (ms)P95 (ms)
Onboarding Import WalletimportWalletToSocialScreen2212202231221223
srpButtonToSrpForm9999100199100
confirmSrpToPwForm24232512425
pwFormToMetricsScreen17171701717
metricsToWalletReadyScreen18181901819
doneButtonToHomeScreen67960380378735803
openAccountMenuToAccountListLoaded294729362956829522956
total4018392341368841124136
Onboarding New WalletcreateWalletToSocialScreen2172162191218219
srpButtonToPwForm1071071070107107
createPwToRecoveryScreen888088
skipBackupToMetricsScreen35353613536
agreeButtonToOnboardingSuccess16161601616
doneButtonToAssetList58448966669642666
total97287310506510251050
Asset DetailsassetClickToPriceChart42344854448
total42344854448
Solana Asset DetailsassetClickToPriceChart71678376783
total71678376783
Import Srp HomeloginToHomeScreen20801887225414521862254
openAccountMenuAfterLogin37334033840
homeAfterImportWithNewWallet270026942712827122712
total47504614487910848304879
Send TransactionsopenSendPageFromHome25252502525
selectTokenToSendFormLoaded20192112121
reviewTransactionToConfirmationPage8468458491846849
total8918838975893897
SwapopenSwapPageFromHome1151141171117117
fetchAndDisplaySwapQuotes289228912893128922893
total301030063015430143015
🌐 Dapp Page Load Benchmarks

Current Commit: b646dc9 | Date: 3/4/2026

📄 Localhost MetaMask Test Dapp

Samples: 100

Summary

  • pageLoadTime-> current mean value: 1.06s (±45ms) 🟡 | historical mean value: 1.06s ⬆️ (historical data)
  • domContentLoaded-> current mean value: 746ms (±43ms) 🟢 | historical mean value: 746ms ⬇️ (historical data)
  • firstContentfulPaint-> current mean value: 84ms (±18ms) 🟢 | historical mean value: 82ms ⬆️ (historical data)

📈 Detailed Results

Metric Mean Std Dev Min Max P95 P99
pageLoadTime 1.06s 45ms 1.02s 1.39s 1.11s 1.39s
domContentLoaded 746ms 43ms 714ms 1.07s 782ms 1.07s
firstPaint 84ms 18ms 64ms 216ms 92ms 216ms
firstContentfulPaint 84ms 18ms 64ms 216ms 92ms 216ms
largestContentfulPaint 0ms 0ms 0ms 0ms 0ms 0ms
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 1.45 KiB (0.03%)
  • ui: -2.73 KiB (-0.03%)
  • common: 442 Bytes (0%)

@david0xd david0xd enabled auto-merge March 4, 2026 18:43
@david0xd david0xd added this pull request to the merge queue Mar 4, 2026
Merged via the queue into main with commit ebc6541 Mar 4, 2026
342 of 347 checks passed
@david0xd david0xd deleted the dd/fix-hw-wallet-errors branch March 4, 2026 19:34
@github-actions github-actions bot locked and limited conversation to collaborators Mar 4, 2026
@metamaskbot metamaskbot added the release-13.22.0 Issue or pull request that will be included in release 13.22.0 label Mar 4, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-13.22.0 Issue or pull request that will be included in release 13.22.0 size-S team-accounts-framework Accounts team team-extension-platform Extension Platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: UI error that is not informative is presented if the user tries to connect MM to Ledger while the SOL/BTC ledger app is opened

5 participants