linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Scott Mayhew <smayhew@redhat.com>
To: dros@monkey.org
Cc: linux-nfs@vger.kernel.org
Subject: [nfsometer PATCH 1/2] cmd.py: redefine CmdErrorCode
Date: Mon, 22 Feb 2016 16:02:10 -0500	[thread overview]
Message-ID: <1456174931-61514-1-git-send-email-smayhew@redhat.com> (raw)

Redefine CmdErrorCode so the error code itself can be checked.

Signed-off-by: Scott Mayhew <smayhew@redhat.com>
---
 nfsometerlib/cmd.py | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/nfsometerlib/cmd.py b/nfsometerlib/cmd.py
index 9b6dbdd..a2ebcef 100644
--- a/nfsometerlib/cmd.py
+++ b/nfsometerlib/cmd.py
@@ -25,7 +25,15 @@ class CmdError(Exception):
     pass
 
 class CmdErrorCode(CmdError):
-    pass
+    def __init__(self, cmd, code, errstr):
+        self.cmd = cmd
+        self.code = code
+        self.errstr = errstr
+
+    def __str__(self):
+        return str.format(
+            'command "{:s}" exited with non-zero status: {:d}{:s}',
+            self.cmd, self.code, self.errstr)
 
 class CmdErrorOut(CmdError):
     pass
@@ -67,8 +75,7 @@ def cmd(args, raiseerrorcode=True, raiseerrorout=True, instr='',
         errstr = '\n%s' % errstr
 
     if raiseerrorcode and ret != 0:
-        raise CmdErrorCode('command "%s" exited with non-zero status: %u%s' %
-                            (args, ret, errstr))
+        raise CmdErrorCode(args, ret, errstr)
 
     if raiseerrorout and errstr:
         raise CmdErrorOut('command "%s" has output to stderr: %s' %
-- 
2.4.3


             reply	other threads:[~2016-02-22 21:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-22 21:02 Scott Mayhew [this message]
2016-02-22 21:02 ` [nfsometer PATCH 2/2] trace.py: Add some more error handling to probe_mounts() Scott Mayhew
2016-03-02 18:40   ` Weston Andros Adamson

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=1456174931-61514-1-git-send-email-smayhew@redhat.com \
    --to=smayhew@redhat.com \
    --cc=dros@monkey.org \
    --cc=linux-nfs@vger.kernel.org \
    /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).