py: handle busy BitBox connection errors
What changed, and why it matters
This change improves a Python helper tool so that if the BitBox hardware wallet is already in use by another program, the user sees a friendly error message instead of a confusing crash traceback. It is a user-experience fix, not a security fix.
No security action required. Treat as a normal UX improvement. If reviewing, verify that the OSError catch is not overly broad for other HID failure modes, but this is a minor code-quality consideration, not a security issue.
Security signals we found
No security-relevant signals present in the diff or commit message.
Exception handling change only; no privilege boundary, input validation, cryptographic, or memory-safety changes.
Evidence from the diff
The commit wraps two calls to hid_device.open_path() in try/except OSError blocks inside py/send_message.py. When open_path raises OSError (e.g., because the HID device is already opened exclusively by another process), the script now prints ‘Could not connect to the BitBox, device may be already connected to another app.’ and exits with status 1. Previously the exception would propagate and produce a Python traceback. The change does not alter access control, cryptography, or device behavior.
Changed components
py/send_message.pyconnect_to_usb_bitbox() functionInspect captured patch +14 / −2
diff --git a/py/send_message.py b/py/send_message.py
index 6875806..447ec2b 100755
--- a/py/send_message.py
+++ b/py/send_message.py
@@ -1820,7 +1820,13 @@ def connect_to_usb_bitbox(debug: bool, use_cache: bool) -> int:
print("Neither bitbox nor bootloader found.")
return 1
hid_device = hid.device()
- hid_device.open_path(bootloader["path"])
+ try:
+ hid_device.open_path(bootloader["path"])
+ except OSError:
+ print(
+ "Could not connect to the BitBox, device may be already connected to another app."
+ )
+ return 1
bootloader_connection = bitbox02.Bootloader(u2fhid.U2FHid(hid_device), bootloader)
boot_app = SendMessageBootloader(bootloader_connection)
return boot_app.run()
@@ -1865,7 +1871,13 @@ def connect_to_usb_bitbox(debug: bool, use_cache: bool) -> int:
config = NoiseConfigNoCache()
hid_device = hid.device()
- hid_device.open_path(bitbox["path"])
+ try:
+ hid_device.open_path(bitbox["path"])
+ except OSError:
+ print(
+ "Could not connect to the BitBox, device may be already connected to another app."
+ )
+ return 1
bitbox_connection = bitbox02.BitBox02(
transport=u2fhid.U2FHid(hid_device), device_info=bitbox, noise_config=config
)
Why this scored 19/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.