Skip to content

Commit 774e041

Browse files
authored
Merge pull request arvydas#123 from robberwick/release/no-libusb-installed
Provide a friendlier exception fhen no usb backend found on unix-like systems
2 parents 419c819 + db29e7e commit 774e041

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-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(

src/blinkstick/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ class BlinkStickException(Exception):
77

88
class NotConnected(BlinkStickException):
99
pass
10+
11+
12+
class USBBackendNotAvailable(BlinkStickException):
13+
pass

0 commit comments

Comments
 (0)