Skip to content

Commit 771b701

Browse files
donaldhkuba-moo
authored andcommitted
tools/net/ynl: Report netlink errors without stacktrace
ynl does not handle NlError exceptions so they get reported like program failures. Handle the NlError exceptions and report the netlink errors more cleanly. Example now: Netlink error: No such file or directory nl_len = 44 (28) nl_flags = 0x300 nl_type = 2 error: -2 extack: {'bad-attr': '.op'} Example before: Traceback (most recent call last): File "/home/donaldh/net-next/./tools/net/ynl/cli.py", line 81, in <module> main() File "/home/donaldh/net-next/./tools/net/ynl/cli.py", line 69, in main reply = ynl.dump(args.dump, attrs) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/donaldh/net-next/tools/net/ynl/lib/ynl.py", line 906, in dump return self._op(method, vals, [], dump=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/donaldh/net-next/tools/net/ynl/lib/ynl.py", line 872, in _op raise NlError(nl_msg) lib.ynl.NlError: Netlink error: No such file or directory nl_len = 44 (28) nl_flags = 0x300 nl_type = 2 error: -2 extack: {'bad-attr': '.op'} Signed-off-by: Donald Hunter <donald.hunter@gmail.com> Link: https://lore.kernel.org/r/20240306231046.97158-3-donald.hunter@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent cecbc52 commit 771b701

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

tools/net/ynl/cli.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import pprint
77
import time
88

9-
from lib import YnlFamily, Netlink
9+
from lib import YnlFamily, Netlink, NlError
1010

1111

1212
class YnlEncoder(json.JSONEncoder):
@@ -66,12 +66,16 @@ def output(msg):
6666
if args.sleep:
6767
time.sleep(args.sleep)
6868

69-
if args.do:
70-
reply = ynl.do(args.do, attrs, args.flags)
71-
output(reply)
72-
if args.dump:
73-
reply = ynl.dump(args.dump, attrs)
74-
output(reply)
69+
try:
70+
if args.do:
71+
reply = ynl.do(args.do, attrs, args.flags)
72+
output(reply)
73+
if args.dump:
74+
reply = ynl.dump(args.dump, attrs)
75+
output(reply)
76+
except NlError as e:
77+
print(e)
78+
exit(1)
7579

7680
if args.ntf:
7781
ynl.check_ntf()

tools/net/ynl/lib/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from .nlspec import SpecAttr, SpecAttrSet, SpecEnumEntry, SpecEnumSet, \
44
SpecFamily, SpecOperation
5-
from .ynl import YnlFamily, Netlink
5+
from .ynl import YnlFamily, Netlink, NlError
66

77
__all__ = ["SpecAttr", "SpecAttrSet", "SpecEnumEntry", "SpecEnumSet",
8-
"SpecFamily", "SpecOperation", "YnlFamily", "Netlink"]
8+
"SpecFamily", "SpecOperation", "YnlFamily", "Netlink", "NlError"]

0 commit comments

Comments
 (0)