[rtems commit] items: Improve ItemCache exception message
Sebastian Huber
sebh at rtems.org
Mon Jul 27 05:39:35 UTC 2020
Module: rtems
Branch: master
Commit: 6a3a6648dcdff1bdef63bb3351b453a9e9d54d6c
Changeset: http://git.rtems.org/rtems/commit/?id=6a3a6648dcdff1bdef63bb3351b453a9e9d54d6c
Author: Sebastian Huber <sebastian.huber at embedded-brains.de>
Date: Mon Jul 27 07:08:34 2020 +0200
items: Improve ItemCache exception message
---
rtemsspec/items.py | 9 +++++++--
rtemsspec/tests/spec-item-cache-2/a.yml | 2 ++
rtemsspec/tests/test_items_itemcache.py | 9 +++++++++
3 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/rtemsspec/items.py b/rtemsspec/items.py
index 06c1352..cdcf451 100644
--- a/rtemsspec/items.py
+++ b/rtemsspec/items.py
@@ -234,8 +234,13 @@ class Item:
def init_parents(self, item_cache: "ItemCache"):
""" Initializes the list of links to parents of this items. """
for data in self._data["links"]:
- link = Link(item_cache[self.to_abs_uid(data["uid"])], data)
- self._links_to_parents.append(link)
+ try:
+ link = Link(item_cache[self.to_abs_uid(data["uid"])], data)
+ self._links_to_parents.append(link)
+ except KeyError as err:
+ msg = (f"item '{self.uid}' links "
+ f"to non-existing item '{data['uid']}'")
+ raise KeyError(msg) from err
def add_link_to_child(self, link: Link):
""" Adds a link to a child item of this items. """
diff --git a/rtemsspec/tests/spec-item-cache-2/a.yml b/rtemsspec/tests/spec-item-cache-2/a.yml
new file mode 100644
index 0000000..d5b8c7d
--- /dev/null
+++ b/rtemsspec/tests/spec-item-cache-2/a.yml
@@ -0,0 +1,2 @@
+links:
+- uid: nix
diff --git a/rtemsspec/tests/test_items_itemcache.py b/rtemsspec/tests/test_items_itemcache.py
index 678ae2b..62aab04 100644
--- a/rtemsspec/tests/test_items_itemcache.py
+++ b/rtemsspec/tests/test_items_itemcache.py
@@ -62,6 +62,15 @@ def test_load(tmpdir):
assert item_cache_3["/d/c"]["v"] == "x"
+def test_load_link_error(tmpdir):
+ config = create_item_cache_config_and_copy_spec(tmpdir,
+ "spec-item-cache-2")
+ with pytest.raises(
+ KeyError,
+ match=r"^\"item '/a' links to non-existing item 'nix'\"$"):
+ ItemCache(config)
+
+
class Mapper(ItemMapper):
def __init__(self, item):
super().__init__(item)
More information about the vc
mailing list