From dc9c6a4436a1fddfb75eee7a3b5d716260cec5f9 Mon Sep 17 00:00:00 2001 From: Artem Egorkine Date: Sun, 20 Oct 2024 00:08:38 +0300 Subject: [PATCH] USB: don't crash when opening a USB device fails --- usb/src/usb.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/usb/src/usb.rs b/usb/src/usb.rs index b61d240..cfd8319 100644 --- a/usb/src/usb.rs +++ b/usb/src/usb.rs @@ -54,7 +54,9 @@ impl Usb { .ok_or(rusb::Error::NotFound)?, )?; */ - let hdl = self.ctx.open_device_with_vid_pid(vid, pid).unwrap(); + let hdl = self.ctx.open_device_with_vid_pid(vid, pid) + .ok_or(rusb::Error::NotFound)?; + Ok(hdl) }