Skip to content

Commit

Permalink
tools: ynl: throw a more meaningful exception if family not supported
Browse files Browse the repository at this point in the history
cli.py currently throws a pure KeyError if kernel doesn't support
a netlink family. Users who did not write ynl (hah) may waste
their time investigating what's wrong with the Python code.
Improve the error message:

Traceback (most recent call last):
  File "/home/kicinski/devel/linux/tools/net/ynl/lib/ynl.py", line 362, in __init__
    self.family = GenlFamily(self.yaml['name'])
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kicinski/devel/linux/tools/net/ynl/lib/ynl.py", line 331, in __init__
    self.genl_family = genl_family_name_to_id[family_name]
                       ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 'netdev'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/kicinski/devel/linux/./tools/net/ynl/cli.py", line 52, in <module>
    main()
  File "/home/kicinski/devel/linux/./tools/net/ynl/cli.py", line 31, in main
    ynl = YnlFamily(args.spec, args.schema)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/kicinski/devel/linux/tools/net/ynl/lib/ynl.py", line 364, in __init__
    raise Exception(f"Family '{self.yaml['name']}' not supported by the kernel")
Exception: Family 'netdev' not supported by the kernel

Signed-off-by: Jakub Kicinski <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Paolo Abeni <[email protected]>
  • Loading branch information
kuba-moo authored and Paolo Abeni committed Apr 11, 2023
1 parent 89863a3 commit ebe3bdc
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tools/net/ynl/lib/ynl.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,10 @@ def __init__(self, def_path, schema=None):
bound_f = functools.partial(self._op, op_name)
setattr(self, op.ident_name, bound_f)

self.family = GenlFamily(self.yaml['name'])
try:
self.family = GenlFamily(self.yaml['name'])
except KeyError:
raise Exception(f"Family '{self.yaml['name']}' not supported by the kernel")

def ntf_subscribe(self, mcast_name):
if mcast_name not in self.family.genl_family['mcast']:
Expand Down

0 comments on commit ebe3bdc

Please sign in to comment.