Replaced error on nonexisting label name with a more descriptive one

Instead of unintuitive Value Error now we have dedicated QubesLabelNotFoundError.
Goal: to make qvm-prefs be less strange when one mixes up gray and grey again.
This commit is contained in:
Marta Marczykowska-Górecka 2020-08-13 20:03:47 +02:00
parent b506586089
commit 6b9528316f
No known key found for this signature in database
GPG Key ID: 9A752C30B26FD04B
3 changed files with 13 additions and 2 deletions

View File

@ -1340,7 +1340,7 @@ class Qubes(qubes.PropertyHolder):
except (KeyError, ValueError): except (KeyError, ValueError):
pass pass
raise KeyError(label) raise qubes.exc.QubesLabelNotFoundError(label)
@asyncio.coroutine @asyncio.coroutine
def setup_pools(self): def setup_pools(self):

View File

@ -208,3 +208,14 @@ class QubesTagNotFoundError(QubesException, KeyError):
def __str__(self): def __str__(self):
# KeyError overrides __str__ method # KeyError overrides __str__ method
return QubesException.__str__(self) return QubesException.__str__(self)
class QubesLabelNotFoundError(QubesException, KeyError):
"""Label does not exists"""
def __init__(self, label):
super().__init__('Label does not exist: {}'.format(label))
self.label = label
def __str__(self):
# KeyError overrides __str__ method
return QubesException.__str__(self)

View File

@ -82,7 +82,7 @@ class TestApp(qubes.tests.TestEmitter):
for l in self.labels.values(): for l in self.labels.values():
if l.name == label: if l.name == label:
return l return l
raise KeyError(label) raise qubes.exc.QubesLabelNotFoundError(label)
def get_pool(self, pool): def get_pool(self, pool):
return self.pools[pool] return self.pools[pool]