Skip to content

Commit 8a084fe

Browse files
committed
Add custom exception to assignment mode and backup
For: QubesOS#645
1 parent a747d55 commit 8a084fe

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

qubes/api/admin.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,7 +1793,9 @@ async def vm_device_set_required(self, endpoint, untrusted_payload):
17931793
try:
17941794
mode = allowed_values[untrusted_payload]
17951795
except KeyError:
1796-
raise qubes.exc.ProtocolError("Invalid assignment mode")
1796+
raise qubes.exc.QubesUnrecognizedDeviceAssignmentMode(
1797+
"Invalid assignment mode"
1798+
)
17971799

17981800
dev = VirtualDevice.from_qarg(self.arg, devclass, self.app.domains)
17991801

@@ -2093,7 +2095,7 @@ async def backup_execute(self):
20932095
try:
20942096
await backup_task
20952097
except asyncio.CancelledError:
2096-
raise qubes.exc.QubesException("Backup cancelled")
2098+
raise qubes.exc.BackupCancelledError()
20972099
finally:
20982100
del self.app.api_admin_running_backups[self.arg]
20992101

qubes/exc.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,11 @@ def __init__(self, msg=None):
244244
class QubesBackupProfileNotFoundError(QubesException):
245245
"""Requested backup profile does not exist."""
246246

247+
def __init__(self, msg=None, profile=None):
248+
super().__init__(
249+
msg or "Backup profile {!r} does not exist".format(profile)
250+
)
251+
247252

248253
class BackupCancelledError(QubesException):
249254
"""Thrown at user when backup was manually cancelled"""
@@ -333,6 +338,12 @@ class DeviceAlreadyAssigned(QubesException, KeyError):
333338
"""
334339

335340

341+
class QubesUnrecognizedDeviceAssignmentMode(ProtocolError):
342+
"""
343+
Device assignment is not as expected.
344+
"""
345+
346+
336347
class UnrecognizedDevice(QubesException, ValueError):
337348
"""
338349
Device identity is not as expected.

0 commit comments

Comments
 (0)