Browse Source

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.
Marta Marczykowska-Górecka 3 years ago
parent
commit
6b9528316f
3 changed files with 13 additions and 2 deletions
  1. 1 1
      qubes/app.py
  2. 11 0
      qubes/exc.py
  3. 1 1
      qubes/tests/vm/__init__.py

+ 1 - 1
qubes/app.py

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

+ 11 - 0
qubes/exc.py

@@ -208,3 +208,14 @@ class QubesTagNotFoundError(QubesException, KeyError):
     def __str__(self):
         # KeyError overrides __str__ method
         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)

+ 1 - 1
qubes/tests/vm/__init__.py

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