From 6ef15afae90a8e925a5482d5a8ea2a98702d54fa Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Fri, 22 Jan 2021 06:39:55 +0100 Subject: 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 3a2d5e34..bcc7ed0a 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 b1aba815..483c8d43 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(): -- cgit v1.2.3