[rtems-central commit] items: Catch all YAML errors

Sebastian Huber sebh at rtems.org
Wed Dec 2 07:01:13 UTC 2020


Module:    rtems-central
Branch:    master
Commit:    3a99494a876290350e7e4eb7b189bd8b308566ce
Changeset: http://git.rtems.org/rtems-central/commit/?id=3a99494a876290350e7e4eb7b189bd8b308566ce

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Dec  2 07:59:41 2020 +0100

items: Catch all YAML errors

---

 rtemsspec/items.py                      | 4 ++--
 rtemsspec/tests/test_items_itemcache.py | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/rtemsspec/items.py b/rtemsspec/items.py
index 12ecfb4..2bbf084 100644
--- a/rtemsspec/items.py
+++ b/rtemsspec/items.py
@@ -495,8 +495,8 @@ def _load_item(path: str, uid: str) -> Any:
     with open(path, "r") as src:
         try:
             data = yaml.safe_load(src.read())
-        except yaml.parser.ParserError as err:
-            msg = ("YAML parser error while loading specification item file "
+        except yaml.YAMLError as err:
+            msg = ("YAML error while loading specification item file "
                    f"'{path}': {str(err)}")
             raise IOError(msg) from err
         data["_file"] = os.path.abspath(path)
diff --git a/rtemsspec/tests/test_items_itemcache.py b/rtemsspec/tests/test_items_itemcache.py
index 4331b33..d90b1e0 100644
--- a/rtemsspec/tests/test_items_itemcache.py
+++ b/rtemsspec/tests/test_items_itemcache.py
@@ -84,10 +84,10 @@ def test_load_link_error(tmpdir):
         ItemCache(config)
 
 
-def test_load_parser_error(tmpdir):
+def test_load_yaml_error(tmpdir):
     config = create_item_cache_config_and_copy_spec(tmpdir,
                                                     "spec-item-cache-3")
-    match = r"""YAML parser error while loading specification item file '.*invalid.yml': while parsing a block mapping
+    match = r"""YAML error while loading specification item file '.*invalid.yml': while parsing a block mapping
 expected <block end>, but found ':'
   in "<unicode string>", line 1, column 1:
     :



More information about the vc mailing list