Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions qubes/device_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand Down
7 changes: 6 additions & 1 deletion qubes/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
)
Expand Down