ledger: throw UserFacingException for OSError
What changed, and why it matters
This is a small user-experience fix for Electrum's Ledger hardware wallet plugin. When the Ledger device disconnects or its Bitcoin app is closed during use, the software previously generated an internal crash report. Now it shows a friendly on-screen message instead. There is no indication this change fixes a security vulnerability or introduces one.
No security action required; routine review/merge as a user-experience improvement.
Security signals we found
No security-relevant code paths modified
Exception handling change only
No cryptographic or authorization logic touched
No input validation or parsing changes
Evidence from the diff
The commit wraps OSError exceptions thrown during Ledger communication in a UserFacingException, converting a low-level disconnection error into a user-visible message. It adds a decorator catch block in electrum/plugins/ledger/ledger.py. The change is defensive and reduces crash-report noise; it does not alter cryptographic operations, trust boundaries, or authentication logic.
Changed components
electrum/plugins/ledger/ledger.pyLedger hardware wallet plugin exception handlingInspect captured patch +5 / −0
diff --git a/electrum/plugins/ledger/ledger.py b/electrum/plugins/ledger/ledger.py
index 17f0848..f10f97f 100644
--- a/electrum/plugins/ledger/ledger.py
+++ b/electrum/plugins/ledger/ledger.py
@@ -137,6 +137,11 @@ def test_pin_unlocked(func):
return func(self, *args, **kwargs)
except SecurityStatusNotSatisfiedError:
raise UserFacingException(_('Your Ledger is locked. Please unlock it.'))
+ except OSError as e:
+ _logger.exception('')
+ raise UserFacingException(
+ _('Communication with Ledger failed. Open the Bitcoin app and try again.') + f'\n{str(e)}',
+ )
return catch_exception
Why this scored 18/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.