summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorStanislav Fomichev <sdf@google.com>2023-03-30 00:16:54 +0200
committerJakub Kicinski <kuba@kernel.org>2023-03-31 08:29:57 +0200
commit48993e22d23ae1bda1db3616f5d9baa4e7b18d35 (patch)
tree680fed9f5f26efb833cf9344e60e91274e1c83fa /tools
parenttools: ynl: populate most of the ethtool spec (diff)
downloadlinux-48993e22d23ae1bda1db3616f5d9baa4e7b18d35.tar.xz
linux-48993e22d23ae1bda1db3616f5d9baa4e7b18d35.zip
tools: ynl: replace print with NlError
Instead of dumping the error on the stdout, make the callee and opportunity to decide what to do with it. This is mostly for the ethtool testing. Signed-off-by: Stanislav Fomichev <sdf@google.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/net/ynl/lib/ynl.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/tools/net/ynl/lib/ynl.py b/tools/net/ynl/lib/ynl.py
index 8778994d40c0..373c0edb5f83 100644
--- a/tools/net/ynl/lib/ynl.py
+++ b/tools/net/ynl/lib/ynl.py
@@ -67,6 +67,14 @@ class Netlink:
NLMSGERR_ATTR_MISS_NEST = 6
+class NlError(Exception):
+ def __init__(self, nl_msg):
+ self.nl_msg = nl_msg
+
+ def __str__(self):
+ return f"Netlink error: {os.strerror(-self.nl_msg.error)}\n{self.nl_msg}"
+
+
class NlAttr:
type_formats = { 'u8' : ('B', 1), 's8' : ('b', 1),
'u16': ('H', 2), 's16': ('h', 2),
@@ -551,9 +559,7 @@ class YnlFamily(SpecFamily):
self._decode_extack(msg, op.attr_set, nl_msg.extack)
if nl_msg.error:
- print("Netlink error:", os.strerror(-nl_msg.error))
- print(nl_msg)
- return
+ raise NlError(nl_msg)
if nl_msg.done:
if nl_msg.extack:
print("Netlink warning:")