Skip to content

Commit 13a7bf2

Browse files
committed
Add custom exception to assignment mode and backup
For: QubesOS#645
1 parent 756fc0d commit 13a7bf2

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

qubes/api/admin.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,7 +1813,7 @@ async def vm_device_set_required(self, endpoint, untrusted_payload):
18131813
try:
18141814
mode = allowed_values[untrusted_payload]
18151815
except KeyError:
1816-
raise qubes.exc.ProtocolError("Invalid assignment mode")
1816+
raise qubes.exc.QubesUnrecognizedDeviceAssignmentMode("Invalid assignment mode")
18171817

18181818
dev = VirtualDevice.from_qarg(self.arg, devclass, self.app.domains)
18191819

@@ -2096,9 +2096,7 @@ async def backup_execute(self):
20962096
qubes.config.backup_profile_dir, self.arg + ".conf"
20972097
)
20982098
if not os.path.exists(profile_path):
2099-
raise qubes.exc.ProtocolError(
2100-
"Backup profile does not exist: {}".format(self.arg)
2101-
)
2099+
raise qubes.exc.QubesBackupProfileNotFoundError(profile=self.arg)
21022100

21032101
if not hasattr(self.app, "api_admin_running_backups"):
21042102
self.app.api_admin_running_backups = {}
@@ -2117,7 +2115,7 @@ async def backup_execute(self):
21172115
try:
21182116
await backup_task
21192117
except asyncio.CancelledError:
2120-
raise qubes.exc.QubesException("Backup cancelled")
2118+
raise qubes.exc.BackupCancelledError()
21212119
finally:
21222120
del self.app.api_admin_running_backups[self.arg]
21232121

@@ -2159,9 +2157,7 @@ async def backup_info(self):
21592157
qubes.config.backup_profile_dir, self.arg + ".conf"
21602158
)
21612159
if not os.path.exists(profile_path):
2162-
raise qubes.exc.ProtocolError(
2163-
"Backup profile does not exist: {}".format(self.arg)
2164-
)
2160+
raise qubes.exc.QubesBackupProfileNotFoundError(profile=self.arg)
21652161

21662162
backup = await self._load_backup_profile(self.arg, skip_passphrase=True)
21672163
return backup.get_backup_summary()

qubes/exc.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,15 @@ def __init__(self, msg=None):
237237
super().__init__(msg or "This feature is not available")
238238

239239

240+
class QubesBackupProfileNotFoundError(QubesException):
241+
"""Thrown at user when backup was manually cancelled"""
242+
243+
def __init__(self, msg=None, profile=None):
244+
super().__init__(
245+
msg or "Backup profile {!r} does not exist".format(profile)
246+
)
247+
248+
240249
class BackupCancelledError(QubesException):
241250
"""Thrown at user when backup was manually cancelled"""
242251

@@ -325,6 +334,12 @@ class DeviceAlreadyAssigned(QubesException, KeyError):
325334
"""
326335

327336

337+
class QubesUnrecognizedDeviceAssignmentMode(ProtocolError):
338+
"""
339+
Device assignment is not as expected.
340+
"""
341+
342+
328343
class UnrecognizedDevice(QubesException, ValueError):
329344
"""
330345
Device identity is not as expected.

0 commit comments

Comments
 (0)