Skip to content

Commit db29e7e

Browse files
committed
feat: handle USB backend errors by raising USBBackendNotAvailable exception
1 parent dde3695 commit db29e7e

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/blinkstick/backends/unix_like.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from blinkstick.constants import VENDOR_ID, PRODUCT_ID
77
from blinkstick.backends.base import BaseBackend
88
from blinkstick.devices import BlinkStickDevice
9-
from blinkstick.exceptions import BlinkStickException
9+
from blinkstick.exceptions import BlinkStickException, USBBackendNotAvailable
1010
from blinkstick.models import SerialDetails
1111

1212

@@ -38,10 +38,18 @@ def _refresh_attached_blinkstick_device(self):
3838
def get_attached_blinkstick_devices(
3939
find_all: bool = True,
4040
) -> list[BlinkStickDevice[usb.core.Device]]:
41-
raw_devices = (
42-
usb.core.find(find_all=find_all, idVendor=VENDOR_ID, idProduct=PRODUCT_ID)
43-
or []
44-
)
41+
try:
42+
raw_devices = (
43+
usb.core.find(
44+
find_all=find_all, idVendor=VENDOR_ID, idProduct=PRODUCT_ID
45+
)
46+
or []
47+
)
48+
except usb.core.NoBackendError:
49+
# TODO: improve this error message to provide more information on how to remediate the problem
50+
raise USBBackendNotAvailable(
51+
"Could not find USB backend. Is libusb installed?"
52+
)
4553
return [
4654
# TODO: refactor this to DRY up the usb.util.get_string calls
4755
BlinkStickDevice(

0 commit comments

Comments
 (0)