netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stanislav Fomichev <sdf@google.com>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, Stanislav Fomichev <sdf@google.com>
Subject: [PATCH net-next v3 3/4] tools: ynl: replace print with NlError
Date: Wed, 29 Mar 2023 15:16:54 -0700	[thread overview]
Message-ID: <20230329221655.708489-4-sdf@google.com> (raw)
In-Reply-To: <20230329221655.708489-1-sdf@google.com>

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>
---
 tools/net/ynl/lib/ynl.py | 12 +++++++++---
 1 file 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 @@ from .nlspec import SpecFamily
     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 @@ genl_family_name_to_id = None
                     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:")
-- 
2.40.0.348.gf938b09366-goog


  parent reply	other threads:[~2023-03-29 22:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-29 22:16 [PATCH net-next v3 0/4] tools: ynl: fill in some gaps of ethtool spec Stanislav Fomichev
2023-03-29 22:16 ` [PATCH net-next v3 1/4] tools: ynl: support byte-order in cli Stanislav Fomichev
2023-03-29 22:16 ` [PATCH net-next v3 2/4] tools: ynl: populate most of the ethtool spec Stanislav Fomichev
2023-03-29 22:16 ` Stanislav Fomichev [this message]
2023-03-29 22:16 ` [PATCH net-next v3 4/4] tools: ynl: ethtool testing tool Stanislav Fomichev
2023-03-31  6:40 ` [PATCH net-next v3 0/4] tools: ynl: fill in some gaps of ethtool spec 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=20230329221655.708489-4-sdf@google.com \
    --to=sdf@google.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).