@@ -50,19 +50,29 @@ def get_attached_blinkstick_devices(
5050 raise USBBackendNotAvailable (
5151 "Could not find USB backend. Is libusb installed?"
5252 )
53- return [
54- # TODO: refactor this to DRY up the usb.util.get_string calls
55- BlinkStickDevice (
56- raw_device = device ,
57- serial_details = SerialDetails (
58- serial = str (usb .util .get_string (device , 3 , 1033 ))
59- ),
60- manufacturer = str (usb .util .get_string (device , 1 , 1033 )),
61- version_attribute = device .bcdDevice ,
62- description = str (usb .util .get_string (device , 2 , 1033 )),
63- )
64- for device in raw_devices
65- ]
53+
54+ try :
55+ devices = [
56+ # TODO: refactor this to DRY up the usb.util.get_string calls
57+ BlinkStickDevice (
58+ raw_device = device ,
59+ serial_details = SerialDetails (
60+ serial = str (usb .util .get_string (device , 3 , 1033 ))
61+ ),
62+ manufacturer = str (usb .util .get_string (device , 1 , 1033 )),
63+ version_attribute = device .bcdDevice ,
64+ description = str (usb .util .get_string (device , 2 , 1033 )),
65+ )
66+ for device in raw_devices
67+ ]
68+ except usb .core .USBError as e :
69+ # if the error is due to a permission issue, raise a more specific exception
70+ if "Operation not permitted" in str (e ):
71+ raise USBBackendNotAvailable (
72+ "Permission denied accessing USB backend. Does a udev rule need to be added?"
73+ )
74+ raise
75+ return devices
6676
6777 @staticmethod
6878 def find_by_serial (serial : str ) -> list [BlinkStickDevice [usb .core .Device ]] | None :
0 commit comments