summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2020-07-27 07:08:34 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2020-07-27 07:08:34 +0200
commit6a3a6648dcdff1bdef63bb3351b453a9e9d54d6c (patch)
tree687af6eb5879b6b6192529b616b5c1512868b467
parent1cf2bec9cba064fd91d3770edad4da250896bf99 (diff)
items: Improve ItemCache exception message
-rw-r--r--rtemsspec/items.py9
-rw-r--r--rtemsspec/tests/spec-item-cache-2/a.yml2
-rw-r--r--rtemsspec/tests/test_items_itemcache.py9
3 files changed, 18 insertions, 2 deletions
diff --git a/rtemsspec/items.py b/rtemsspec/items.py
index 06c13525..cdcf451d 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 00000000..d5b8c7db
--- /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 678ae2b2..62aab04e 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)