← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~jugmac00/lpcraft:rename-YAMLError-into-ConfigurationError into lpcraft:main

 

Jürgen Gmach has proposed merging ~jugmac00/lpcraft:rename-YAMLError-into-ConfigurationError into lpcraft:main.

Commit message:
Rename YAMLError into ConfigurationError

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~jugmac00/lpcraft/+git/lpcraft/+merge/413419
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~jugmac00/lpcraft:rename-YAMLError-into-ConfigurationError into lpcraft:main.
diff --git a/lpcraft/commands/tests/test_run.py b/lpcraft/commands/tests/test_run.py
index e9a93ea..3872f20 100644
--- a/lpcraft/commands/tests/test_run.py
+++ b/lpcraft/commands/tests/test_run.py
@@ -14,7 +14,7 @@ from fixtures import TempDir
 from testtools.matchers import MatchesStructure
 
 from lpcraft.commands.tests import CommandBaseTestCase
-from lpcraft.errors import CommandError, YAMLError
+from lpcraft.errors import CommandError, ConfigurationError
 from lpcraft.providers._lxd import LXDProvider, _LXDLauncher
 from lpcraft.providers.tests import FakeLXDInstaller
 
@@ -94,7 +94,9 @@ class TestRun(RunBaseTestCase):
             MatchesStructure.byEquality(
                 exit_code=1,
                 errors=[
-                    YAMLError("Couldn't find config file '.launchpad.yaml'")
+                    ConfigurationError(
+                        "Couldn't find config file '.launchpad.yaml'"
+                    )
                 ],
             ),
         )
@@ -1028,7 +1030,9 @@ class TestRunOne(RunBaseTestCase):
             MatchesStructure.byEquality(
                 exit_code=1,
                 errors=[
-                    YAMLError("Couldn't find config file '.launchpad.yaml'")
+                    ConfigurationError(
+                        "Couldn't find config file '.launchpad.yaml'"
+                    )
                 ],
             ),
         )
diff --git a/lpcraft/errors.py b/lpcraft/errors.py
index 9f289b4..6f0f7c3 100644
--- a/lpcraft/errors.py
+++ b/lpcraft/errors.py
@@ -5,7 +5,7 @@
 
 __all__ = [
     "CommandError",
-    "YAMLError",
+    "ConfigurationError",
 ]
 
 from typing import Any
@@ -25,5 +25,5 @@ class CommandError(CraftError):
         return str(self) == str(other) and self.retcode == other.retcode
 
 
-class YAMLError(CommandError):
+class ConfigurationError(CommandError):
     """Error reading YAML file."""
diff --git a/lpcraft/plugin/manager.py b/lpcraft/plugin/manager.py
index ad8ec66..f2cf7b9 100644
--- a/lpcraft/plugin/manager.py
+++ b/lpcraft/plugin/manager.py
@@ -1,7 +1,7 @@
 import pluggy
 
 from lpcraft.config import Job
-from lpcraft.errors import YAMLError
+from lpcraft.errors import ConfigurationError
 from lpcraft.plugin import hookspecs
 from lpcraft.plugin.lib import InternalPlugins
 from lpcraft.plugins import PLUGINS
@@ -17,7 +17,7 @@ def get_plugin_manager(job: Job) -> pluggy.PluginManager:
     # register builtin plugins
     if job.plugin:
         if job.plugin not in PLUGINS:
-            raise YAMLError("Unknown plugin")
+            raise ConfigurationError("Unknown plugin")
         pm.register(PLUGINS[job.plugin](job))
 
     return pm
diff --git a/lpcraft/plugin/tests/test_plugins.py b/lpcraft/plugin/tests/test_plugins.py
index 270ad7a..b833b60 100644
--- a/lpcraft/plugin/tests/test_plugins.py
+++ b/lpcraft/plugin/tests/test_plugins.py
@@ -9,7 +9,7 @@ from unittest.mock import ANY, Mock, call, patch
 from craft_providers.lxd import LXC, launch
 
 from lpcraft.commands.tests import CommandBaseTestCase
-from lpcraft.errors import YAMLError
+from lpcraft.errors import ConfigurationError
 from lpcraft.providers._lxd import LXDProvider, _LXDLauncher
 from lpcraft.providers.tests import FakeLXDInstaller
 
@@ -105,7 +105,7 @@ class TestPlugins(CommandBaseTestCase):
         result = self.run_command("run")
 
         self.assertEqual(1, result.exit_code)
-        self.assertEqual([YAMLError("Unknown plugin")], result.errors)
+        self.assertEqual([ConfigurationError("Unknown plugin")], result.errors)
 
     @patch("lpcraft.commands.run.get_provider")
     @patch("lpcraft.commands.run.get_host_architecture", return_value="amd64")
diff --git a/lpcraft/tests/test_utils.py b/lpcraft/tests/test_utils.py
index e33a40c..52b42e3 100644
--- a/lpcraft/tests/test_utils.py
+++ b/lpcraft/tests/test_utils.py
@@ -10,7 +10,7 @@ from fixtures import TempDir
 from systemfixtures import FakeProcesses
 from testtools import TestCase
 
-from lpcraft.errors import YAMLError
+from lpcraft.errors import ConfigurationError
 from lpcraft.utils import ask_user, get_host_architecture, load_yaml
 
 
@@ -27,7 +27,7 @@ class TestLoadYAML(TestCase):
     def test_no_file(self):
         path = self.tempdir / "testfile.yaml"
         self.assertRaisesRegex(
-            YAMLError,
+            ConfigurationError,
             re.escape(f"Couldn't find config file {str(path)!r}"),
             load_yaml,
             path,
@@ -37,7 +37,7 @@ class TestLoadYAML(TestCase):
         path = self.tempdir / "testfile.yaml"
         path.mkdir()
         self.assertRaisesRegex(
-            YAMLError,
+            ConfigurationError,
             re.escape(f"Couldn't find config file {str(path)!r}"),
             load_yaml,
             path,
@@ -47,7 +47,7 @@ class TestLoadYAML(TestCase):
         path = self.tempdir / "testfile.yaml"
         path.write_text("foo: [1, 2\n")
         self.assertRaisesRegex(
-            YAMLError,
+            ConfigurationError,
             re.escape(
                 f"Failed to read/parse config file {str(path)!r}: "
                 "while parsing a flow sequence"
@@ -60,7 +60,7 @@ class TestLoadYAML(TestCase):
         path = self.tempdir / "testfile.yaml"
         path.write_text("- foo\n")
         self.assertRaisesRegex(
-            YAMLError,
+            ConfigurationError,
             re.escape(f"Config file {str(path)!r} does not define a mapping"),
             load_yaml,
             path,
diff --git a/lpcraft/utils.py b/lpcraft/utils.py
index afddfdb..cd70e07 100644
--- a/lpcraft/utils.py
+++ b/lpcraft/utils.py
@@ -15,23 +15,25 @@ from typing import Any, Dict
 
 import yaml
 
-from lpcraft.errors import YAMLError
+from lpcraft.errors import ConfigurationError
 
 
 def load_yaml(path: Path) -> Dict[Any, Any]:
     """Return the content of a YAML file."""
     if not path.is_file():
-        raise YAMLError(f"Couldn't find config file {str(path)!r}")
+        raise ConfigurationError(f"Couldn't find config file {str(path)!r}")
     try:
         with path.open("rb") as f:
             loaded = yaml.safe_load(f)
         if not isinstance(loaded, dict):
-            raise YAMLError(
+            raise ConfigurationError(
                 f"Config file {str(path)!r} does not define a mapping"
             )
         return loaded
-    except (yaml.error.YAMLError, OSError) as e:
-        raise YAMLError(f"Failed to read/parse config file {str(path)!r}: {e}")
+    except (yaml.error.ConfigurationError, OSError) as e:
+        raise ConfigurationError(
+            f"Failed to read/parse config file {str(path)!r}: {e}"
+        )
 
 
 @lru_cache