Commit 7582113c authored by Jakub Kicinski's avatar Jakub Kicinski

tools: ynl: add more info to KeyErrors on missing attrs

When developing specs its useful to know which attr space
YNL was trying to find an attribute in on key error.

Instead of printing:
 KeyError: 0
add info about the space:
 Exception: Space 'vport' has no attribute with value '0'
Reviewed-by: default avatarDonald Hunter <donald.hunter@gmail.com>
Link: https://lore.kernel.org/r/20230814205627.2914583-4-kuba@kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent ded67d90
...@@ -395,7 +395,10 @@ class YnlFamily(SpecFamily): ...@@ -395,7 +395,10 @@ class YnlFamily(SpecFamily):
self.family.genl_family['mcast'][mcast_name]) self.family.genl_family['mcast'][mcast_name])
def _add_attr(self, space, name, value): def _add_attr(self, space, name, value):
try:
attr = self.attr_sets[space][name] attr = self.attr_sets[space][name]
except KeyError:
raise Exception(f"Space '{space}' has no attribute '{name}'")
nl_type = attr.value nl_type = attr.value
if attr["type"] == 'nest': if attr["type"] == 'nest':
nl_type |= Netlink.NLA_F_NESTED nl_type |= Netlink.NLA_F_NESTED
...@@ -450,7 +453,10 @@ class YnlFamily(SpecFamily): ...@@ -450,7 +453,10 @@ class YnlFamily(SpecFamily):
attr_space = self.attr_sets[space] attr_space = self.attr_sets[space]
rsp = dict() rsp = dict()
for attr in attrs: for attr in attrs:
try:
attr_spec = attr_space.attrs_by_val[attr.type] attr_spec = attr_space.attrs_by_val[attr.type]
except KeyError:
raise Exception(f"Space '{space}' has no attribute with value '{attr.type}'")
if attr_spec["type"] == 'nest': if attr_spec["type"] == 'nest':
subdict = self._decode(NlAttrs(attr.raw), attr_spec['nested-attributes']) subdict = self._decode(NlAttrs(attr.raw), attr_spec['nested-attributes'])
decoded = subdict decoded = subdict
...@@ -479,7 +485,10 @@ class YnlFamily(SpecFamily): ...@@ -479,7 +485,10 @@ class YnlFamily(SpecFamily):
def _decode_extack_path(self, attrs, attr_set, offset, target): def _decode_extack_path(self, attrs, attr_set, offset, target):
for attr in attrs: for attr in attrs:
try:
attr_spec = attr_set.attrs_by_val[attr.type] attr_spec = attr_set.attrs_by_val[attr.type]
except KeyError:
raise Exception(f"Space '{attr_set.name}' has no attribute with value '{attr.type}'")
if offset > target: if offset > target:
break break
if offset == target: if offset == target:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment