From b8feb4ec40eebff3496e775cdb44461b4411c660 Mon Sep 17 00:00:00 2001 From: Chris Pick Date: Mon, 1 Jul 2024 21:31:21 -0400 Subject: [PATCH] Improve USB no backend available message Provide a more descriptive error message when pyusb can't find a backend USB library. --- tools/updater/precursorupdater/precursorupdater.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/updater/precursorupdater/precursorupdater.py b/tools/updater/precursorupdater/precursorupdater.py index 85c04a093..7f61b59fd 100755 --- a/tools/updater/precursorupdater/precursorupdater.py +++ b/tools/updater/precursorupdater/precursorupdater.py @@ -548,10 +548,13 @@ def get_with_progress(url, name='Downloading'): return ret def get_usb_interface(config=False, peek=None, override_csr=None, force=False): - dev = usb.core.find(idProduct=0x5bf0, idVendor=0x1209) + try: + dev = usb.core.find(idProduct=0x5bf0, idVendor=0x1209) + except usb.core.NoBackendError: + raise ValueError('No USB library backend available (eg Libusb, OpenUSB, etc).\nSee: https://github.com/pyusb/pyusb/blob/master/docs/faq.rst#how-do-i-fix-no-backend-available-errors') if dev is None: - raise ValueError('Precursor device not found') + raise ValueError('Precursor device not found. Please check the USB cable and ensure that `usb debug` was run in Shellchat') dev.set_configuration() if config: @@ -658,8 +661,8 @@ def main(): # initial check to see if the Precursor device is there try: (locs, pc_usb) = get_usb_interface(args.config, args.peek, args.override_csr, args.force) - except ValueError: - print("Precursor device not found. Please check the USB cable and ensure that `usb debug` was run in Shellchat") + except ValueError as e: + print(str(e)) exit(1) if args.config: