diff --git a/src/blinkstick/backends/unix_like.py b/src/blinkstick/backends/unix_like.py index 052d9f1..db6179f 100644 --- a/src/blinkstick/backends/unix_like.py +++ b/src/blinkstick/backends/unix_like.py @@ -6,7 +6,7 @@ from blinkstick.constants import VENDOR_ID, PRODUCT_ID from blinkstick.backends.base import BaseBackend from blinkstick.devices import BlinkStickDevice -from blinkstick.exceptions import BlinkStickException +from blinkstick.exceptions import BlinkStickException, USBBackendNotAvailable from blinkstick.models import SerialDetails @@ -38,10 +38,18 @@ def _refresh_attached_blinkstick_device(self): def get_attached_blinkstick_devices( find_all: bool = True, ) -> list[BlinkStickDevice[usb.core.Device]]: - raw_devices = ( - usb.core.find(find_all=find_all, idVendor=VENDOR_ID, idProduct=PRODUCT_ID) - or [] - ) + try: + raw_devices = ( + usb.core.find( + find_all=find_all, idVendor=VENDOR_ID, idProduct=PRODUCT_ID + ) + or [] + ) + except usb.core.NoBackendError: + # TODO: improve this error message to provide more information on how to remediate the problem + raise USBBackendNotAvailable( + "Could not find USB backend. Is libusb installed?" + ) return [ # TODO: refactor this to DRY up the usb.util.get_string calls BlinkStickDevice( diff --git a/src/blinkstick/exceptions.py b/src/blinkstick/exceptions.py index 86f6f51..1cc2d84 100644 --- a/src/blinkstick/exceptions.py +++ b/src/blinkstick/exceptions.py @@ -7,3 +7,7 @@ class BlinkStickException(Exception): class NotConnected(BlinkStickException): pass + + +class USBBackendNotAvailable(BlinkStickException): + pass