diff --git a/qubes/device_protocol.py b/qubes/device_protocol.py index 00b4387e4..51c5a5f2d 100644 --- a/qubes/device_protocol.py +++ b/qubes/device_protocol.py @@ -1369,7 +1369,9 @@ def devices(self) -> List[DeviceInfo]: @property def device(self) -> DeviceInfo: """ - Get single DeviceInfo object or raise an error. + Get single DeviceInfo object or UnknownDevice, if the device has + not been found. + If there are more devices than one matching, raise ProtocolError. If port id is set we have exactly one device since we can attach ony one device to one port. @@ -1380,7 +1382,7 @@ def device(self) -> DeviceInfo: return devices[0] if len(devices) > 1: raise ProtocolError("Too many devices matches to assignment") - raise ProtocolError("No devices matches to assignment") + return UnknownDevice(port=self.port, device_id=self.device_id) @property def port(self) -> Port: diff --git a/qubes/devices.py b/qubes/devices.py index e494432d5..78a977ac6 100644 --- a/qubes/devices.py +++ b/qubes/devices.py @@ -197,8 +197,13 @@ async def attach(self, assignment: DeviceAssignment): try: device = assignment.device + if isinstance(device, UnknownDevice): + # assignment matches no devices + raise ProtocolError( + f"Cannot attach unknown {assignment.devclass} device." + ) except ProtocolError: - # assignment matches no or top many devices + # assignment matches too many devices raise ProtocolError( f"Cannot attach ambiguous {assignment.devclass} device." )