public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Heiko Thiery <heiko.thiery@gmail.com>
To: u-boot@lists.denx.de
Cc: Stefano Babic <sbabic@denx.de>,
	Fabio Estevam <festevam@gmail.com>,
	Michael Walle <michael@walle.cc>, Simon Glass <sjg@chromium.org>,
	Heiko Thiery <heiko.thiery@gmail.com>
Subject: [RFC 1/2] patman: introduce RunException
Date: Thu,  4 Nov 2021 19:52:32 +0100	[thread overview]
Message-ID: <20211104185231.2927-2-heiko.thiery@gmail.com> (raw)
In-Reply-To: <20211104185231.2927-1-heiko.thiery@gmail.com>

The RunException will be throws when the a command's return_code is not
equal zero. With this an external caller can catch that and has access
to the command/args, the result code, the stdout and stderr output.

Signed-off-by: Heiko Thiery <heiko.thiery@gmail.com>
---
 tools/patman/tools.py | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/tools/patman/tools.py b/tools/patman/tools.py
index 710f1fdcd3..ca1c9114ab 100644
--- a/tools/patman/tools.py
+++ b/tools/patman/tools.py
@@ -313,6 +313,18 @@ def GetTargetCompileTool(name, cross_compile=None):
         target_name = name
     return target_name, extra_args
 
+class RunException(Exception):
+    """Exception that is thrown when the command fails"""
+    def __init__(self, args, result):
+        self.args = args
+        self.stdout = result.stdout.strip()
+        self.stderr = result.stderr.strip()
+        self.return_code = result.return_code
+
+    def __str__(self):
+        return ("Error %d running '%s': %s" %
+               (self.return_code,' '.join(self.args), self.stderr))
+
 def Run(name, *args, **kwargs):
     """Run a tool with some arguments
 
@@ -349,9 +361,7 @@ def Run(name, *args, **kwargs):
         result = command.RunPipe([all_args], capture=True, capture_stderr=True,
                                  env=env, raise_on_error=False, binary=binary)
         if result.return_code:
-            raise Exception("Error %d running '%s': %s" %
-               (result.return_code,' '.join(all_args),
-                result.stderr))
+            raise RunException(all_args, result)
         return result.stdout
     except:
         if env and not PathHasFile(env['PATH'], name):
-- 
2.30.2


  reply	other threads:[~2021-11-04 18:53 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-04 18:52 [RFC 0/2] Do not stop with an error when mkimage fails Heiko Thiery
2021-11-04 18:52 ` Heiko Thiery [this message]
2021-11-05  2:02   ` [RFC 1/2] patman: introduce RunException Simon Glass
2021-11-04 18:52 ` [RFC 2/2] binman: catch RunException for mkimage runtime failure Heiko Thiery
2021-11-05  2:02   ` Simon Glass
2021-11-05  7:49     ` Heiko Thiery
2021-11-05 16:12       ` Simon Glass
2021-11-04 19:12 ` [RFC 0/2] Do not stop with an error when mkimage fails Wolfgang Denk
2021-11-04 19:31   ` Heiko Thiery
2021-11-07 14:48     ` Wolfgang Denk
2021-11-09 19:21       ` Heiko Thiery
2021-11-09 19:42         ` Tom Rini
2021-11-10  0:18           ` Rasmus Villemoes
2021-11-10  0:26             ` Rasmus Villemoes
2021-11-10  1:37               ` Tom Rini
2021-11-10  8:28                 ` Michael Walle
2021-11-10 16:31                   ` Simon Glass
2021-11-11 12:29               ` Wolfgang Denk
2021-11-10  0:58           ` Simon Glass
2021-11-11 12:27           ` Wolfgang Denk
2021-11-11 15:04             ` Tom Rini
2021-11-11 12:24         ` Wolfgang Denk
2021-11-11 13:54           ` Heiko Thiery

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=20211104185231.2927-2-heiko.thiery@gmail.com \
    --to=heiko.thiery@gmail.com \
    --cc=festevam@gmail.com \
    --cc=michael@walle.cc \
    --cc=sbabic@denx.de \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /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