[rtems-central commit] items: Improve identifier to item error message

Sebastian Huber sebh at rtems.org
Fri Jan 22 05:55:26 UTC 2021


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Jan 22 06:39:55 2021 +0100

items: Improve identifier to item error message

---

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

diff --git a/rtemsspec/items.py b/rtemsspec/items.py
index 3a2d5e3..bcc7ed0 100644
--- a/rtemsspec/items.py
+++ b/rtemsspec/items.py
@@ -502,13 +502,18 @@ class ItemMapper:
         else:
             uid, key_path = uid_key_path, "/_uid"
         if uid == ".":
-            if item is None:
-                item = self._item
             if prefix is None:
                 prefix = "/".join(self._prefix)
+            if item is None:
+                item = self._item
         else:
-            item = self._item.map(uid)
             prefix = ""
+            try:
+                item = self._item.map(uid)
+            except KeyError as err:
+                msg = (f"item '{uid}' relative to {self._item.spec} "
+                       f"specified by '{identifier}' does not exist")
+                raise ValueError(msg) from err
         key_path = normalize_key_path(key_path, prefix)
         value = item.get_by_normalized_key_path(key_path,
                                                 self.get_value_map(item))
diff --git a/rtemsspec/tests/test_items_itemcache.py b/rtemsspec/tests/test_items_itemcache.py
index b1aba81..483c8d4 100644
--- a/rtemsspec/tests/test_items_itemcache.py
+++ b/rtemsspec/tests/test_items_itemcache.py
@@ -161,6 +161,9 @@ def test_item_mapper(tmpdir):
     match = r"substitution for spec:/p using prefix 'blub' failed for text: \${}"
     with pytest.raises(ValueError, match=match):
         mapper.substitute("${}", item, "blub")
+    match = r"item 'boom' relative to spec:/p specified by 'boom:bam' does not exist"
+    with pytest.raises(ValueError, match=match):
+        mapper.map("boom:bam", item, "blub")
 
 
 def test_empty_item_mapper():



More information about the vc mailing list