Skip to content

Commit 5b2c8c4

Browse files
lexfreiclaude
andcommitted
fix(ble): handle BLEError with user-friendly messages
Replace raw tracebacks with helpful error messages that explain: - What went wrong - Possible causes - How to fix it Covers all BLEError cases: - Device not found (BLE disabled, sleep mode, out of range) - Multiple devices found (need to specify which one) - Write errors (pairing PIN, Linux bluetooth group) - Read errors (device disconnected) Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Aleksei Sviridkin <f@lex.la>
1 parent b26d80f commit 5b2c8c4

1 file changed

Lines changed: 54 additions & 7 deletions

File tree

meshtastic/__main__.py

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,13 +1365,60 @@ def common():
13651365
print(f"Found: name='{x.name}' address='{x.address}'")
13661366
meshtastic.util.our_exit("BLE scan finished", 0)
13671367
elif args.ble:
1368-
client = BLEInterface(
1369-
args.ble if args.ble != "any" else None,
1370-
debugOut=logfile,
1371-
noProto=args.noproto,
1372-
noNodes=args.no_nodes,
1373-
timeout=args.timeout,
1374-
)
1368+
try:
1369+
client = BLEInterface(
1370+
args.ble if args.ble != "any" else None,
1371+
debugOut=logfile,
1372+
noProto=args.noproto,
1373+
noNodes=args.no_nodes,
1374+
timeout=args.timeout,
1375+
)
1376+
except BLEInterface.BLEError as e:
1377+
msg = str(e)
1378+
if "No Meshtastic BLE peripheral" in msg:
1379+
meshtastic.util.our_exit(
1380+
"BLE device not found.\n\n"
1381+
"Possible causes:\n"
1382+
" - Bluetooth is disabled on the Meshtastic device\n"
1383+
" - Device is in deep sleep mode\n"
1384+
" - Device is out of range\n\n"
1385+
"Try:\n"
1386+
" - Press the reset button on your device\n"
1387+
" - Run 'meshtastic --ble-scan' to see available devices",
1388+
1,
1389+
)
1390+
elif "More than one" in msg:
1391+
meshtastic.util.our_exit(
1392+
"Multiple Meshtastic BLE devices found.\n\n"
1393+
"Please specify which device to connect to:\n"
1394+
" - Run 'meshtastic --ble-scan' to list devices\n"
1395+
" - Use 'meshtastic --ble <name_or_address>' to connect",
1396+
1,
1397+
)
1398+
elif "Error writing BLE" in msg:
1399+
meshtastic.util.our_exit(
1400+
"Failed to write to BLE device.\n\n"
1401+
"Possible causes:\n"
1402+
" - Device requires pairing PIN (check device screen)\n"
1403+
" - On Linux: user not in 'bluetooth' group\n"
1404+
" - Connection was interrupted\n\n"
1405+
"Try:\n"
1406+
" - Restart Bluetooth on your computer\n"
1407+
" - Reset the Meshtastic device",
1408+
1,
1409+
)
1410+
elif "Error reading BLE" in msg:
1411+
meshtastic.util.our_exit(
1412+
"Failed to read from BLE device.\n\n"
1413+
"The device may have disconnected unexpectedly.\n\n"
1414+
"Try:\n"
1415+
" - Move closer to the device\n"
1416+
" - Reset the Meshtastic device\n"
1417+
" - Restart Bluetooth on your computer",
1418+
1,
1419+
)
1420+
else:
1421+
meshtastic.util.our_exit(f"BLE error: {e}", 1)
13751422
elif args.host:
13761423
try:
13771424
if ":" in args.host:

0 commit comments

Comments
 (0)