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

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


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

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

items: Improve identifier to value error message

---

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

diff --git a/rtemsspec/items.py b/rtemsspec/items.py
index bcc7ed0..666f631 100644
--- a/rtemsspec/items.py
+++ b/rtemsspec/items.py
@@ -515,8 +515,13 @@ class ItemMapper:
                        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))
+        try:
+            value = item.get_by_normalized_key_path(key_path,
+                                                    self.get_value_map(item))
+        except Exception as err:
+            msg = (f"cannot get value for '{key_path}' of {item.spec} "
+                   f"specified by '{identifier}'")
+            raise ValueError(msg) from err
         for func in pipes:
             value = getattr(self, func)(value)
         return item, key_path, value
diff --git a/rtemsspec/tests/test_items_itemcache.py b/rtemsspec/tests/test_items_itemcache.py
index 483c8d4..2e6c64c 100644
--- a/rtemsspec/tests/test_items_itemcache.py
+++ b/rtemsspec/tests/test_items_itemcache.py
@@ -164,6 +164,9 @@ def test_item_mapper(tmpdir):
     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")
+    match = r"cannot get value for 'blub/bam' of spec:/p specified by '.:bam'"
+    with pytest.raises(ValueError, match=match):
+        mapper.map(".:bam", item, "blub")
 
 
 def test_empty_item_mapper():



More information about the vc mailing list