From: Donald Hunter <donald.hunter@gmail.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: davem@davemloft.net, netdev@vger.kernel.org,
edumazet@google.com, pabeni@redhat.com
Subject: Re: [PATCH net-next 3/3] tools: ynl: add more info to KeyErrors on missing attrs
Date: Tue, 15 Aug 2023 09:15:30 +0100 [thread overview]
Message-ID: <m2o7j8k9gd.fsf@gmail.com> (raw)
In-Reply-To: <20230814205627.2914583-4-kuba@kernel.org> (Jakub Kicinski's message of "Mon, 14 Aug 2023 13:56:27 -0700")
Jakub Kicinski <kuba@kernel.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@kernel.org>
> ---
> CC: donald.hunter@gmail.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@gmail.com>
next prev parent reply other threads:[~2023-08-15 8:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-14 20:56 [PATCH net-next 0/3] net: warn about attempts to register negative ifindex Jakub Kicinski
2023-08-14 20:56 ` [PATCH net-next 1/3] " Jakub Kicinski
2023-08-15 7:02 ` Leon Romanovsky
2023-08-14 20:56 ` [PATCH net-next 2/3] netlink: specs: add ovs_vport new command Jakub Kicinski
2023-08-15 8:06 ` Donald Hunter
2023-08-14 20:56 ` [PATCH net-next 3/3] tools: ynl: add more info to KeyErrors on missing attrs Jakub Kicinski
2023-08-15 8:15 ` Donald Hunter [this message]
2023-08-16 2:40 ` [PATCH net-next 0/3] net: warn about attempts to register negative ifindex patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2o7j8k9gd.fsf@gmail.com \
--to=donald.hunter@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).