Skip to content

Commit

Permalink
tools: ynl: replace print with NlError
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Stanislav Fomichev authored and Jakub Kicinski committed Mar 31, 2023
1 parent a353318 commit 48993e2
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions tools/net/ynl/lib/ynl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -551,9 +559,7 @@ def _op(self, method, vals, dump=False):
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:")
Expand Down

0 comments on commit 48993e2

Please sign in to comment.