[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <m2o7j8k9gd.fsf@gmail.com>
Date: Tue, 15 Aug 2023 09:15:30 +0100
From: Donald Hunter <donald.hunter@...il.com>
To: Jakub Kicinski <kuba@...nel.org>
Cc: davem@...emloft.net, netdev@...r.kernel.org, edumazet@...gle.com,
pabeni@...hat.com
Subject: Re: [PATCH net-next 3/3] tools: ynl: add more info to KeyErrors on
missing attrs
Jakub Kicinski <kuba@...nel.org> writes:
> 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'
>
> Signed-off-by: Jakub Kicinski <kuba@...nel.org>
> ---
> CC: donald.hunter@...il.com
> ---
> tools/net/ynl/lib/ynl.py | 15 ++++++++++++---
> 1 file changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
> index 3ca28d4bcb18..6951bcc7efdc 100644
> --- a/tools/net/ynl/lib/ynl.py
> +++ b/tools/net/ynl/lib/ynl.py
> @@ -395,7 +395,10 @@ genl_family_name_to_id = None
> self.family.genl_family['mcast'][mcast_name])
>
> def _add_attr(self, space, name, value):
> - attr = self.attr_sets[space][name]
> + try:
> + attr = self.attr_sets[space][name]
> + except KeyError:
> + raise Exception(f"Space '{space}' has no attribute '{name}'")
> nl_type = attr.value
> if attr["type"] == 'nest':
> nl_type |= Netlink.NLA_F_NESTED
> @@ -450,7 +453,10 @@ genl_family_name_to_id = None
> attr_space = self.attr_sets[space]
> rsp = dict()
> for attr in attrs:
> - attr_spec = attr_space.attrs_by_val[attr.type]
> + try:
> + 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':
> subdict = self._decode(NlAttrs(attr.raw), attr_spec['nested-attributes'])
> decoded = subdict
> @@ -479,7 +485,10 @@ genl_family_name_to_id = None
>
> def _decode_extack_path(self, attrs, attr_set, offset, target):
> for attr in attrs:
> - attr_spec = attr_set.attrs_by_val[attr.type]
> + try:
> + 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:
> break
> if offset == target:
Reviewed-by: Donald Hunter <donald.hunter@...il.com>
Powered by blists - more mailing lists