Make incorrect label name error more descriptive
Instead of unintuitive Value Error now we have dedicated QubesLabelNotFoundError.
This commit is contained in:
parent
72f565a36b
commit
fe583cd88e
@ -250,7 +250,7 @@ class QubesBase(qubesadmin.base.PropertyHolder):
|
|||||||
def get_label(self, label):
|
def get_label(self, label):
|
||||||
"""Get label as identified by index or name
|
"""Get label as identified by index or name
|
||||||
|
|
||||||
:throws KeyError: when label is not found
|
:throws QubesLabelNotFoundError: when label is not found
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# first search for name, verbatim
|
# first search for name, verbatim
|
||||||
@ -264,7 +264,7 @@ class QubesBase(qubesadmin.base.PropertyHolder):
|
|||||||
for i in self.labels.values():
|
for i in self.labels.values():
|
||||||
if i.index == int(label):
|
if i.index == int(label):
|
||||||
return i
|
return i
|
||||||
raise KeyError(label)
|
raise qubesadmin.exc.QubesLabelNotFoundError(label)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_vm_class(clsname):
|
def get_vm_class(clsname):
|
||||||
|
@ -138,6 +138,13 @@ class QubesTagNotFoundError(QubesException, KeyError):
|
|||||||
return QubesException.__str__(self)
|
return QubesException.__str__(self)
|
||||||
|
|
||||||
|
|
||||||
|
class QubesLabelNotFoundError(QubesException, KeyError):
|
||||||
|
"""Label does not exists"""
|
||||||
|
def __str__(self):
|
||||||
|
# KeyError overrides __str__ method
|
||||||
|
return QubesException.__str__(self)
|
||||||
|
|
||||||
|
|
||||||
class StoragePoolException(QubesException):
|
class StoragePoolException(QubesException):
|
||||||
''' A general storage exception '''
|
''' A general storage exception '''
|
||||||
|
|
||||||
|
@ -278,6 +278,13 @@ class TC_10_QubesBase(qubesadmin.tests.QubesTestCase):
|
|||||||
self.assertEqual(label.name, 'red')
|
self.assertEqual(label.name, 'red')
|
||||||
self.assertAllCalled()
|
self.assertAllCalled()
|
||||||
|
|
||||||
|
def test_021_get_nonexistant_label(self):
|
||||||
|
self.app.expected_calls[('dom0', 'admin.label.List', None, None)] = \
|
||||||
|
b'0\x00red\nblue\n'
|
||||||
|
with self.assertRaises(qubesadmin.exc.QubesLabelNotFoundError):
|
||||||
|
self.app.get_label('green')
|
||||||
|
self.assertAllCalled()
|
||||||
|
|
||||||
def clone_setup_common_calls(self, src, dst):
|
def clone_setup_common_calls(self, src, dst):
|
||||||
# have each property type with default=no, each special-cased,
|
# have each property type with default=no, each special-cased,
|
||||||
# and some with default=yes
|
# and some with default=yes
|
||||||
|
Loading…
Reference in New Issue
Block a user