]> git.ipfire.org Git - pbs.git/commitdiff
backend: command: Evaluate return code and raise errors
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 25 Oct 2022 09:33:07 +0000 (09:33 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 25 Oct 2022 09:33:40 +0000 (09:33 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/__init__.py
src/buildservice/errors.py

index d570e2634220b812f69cdc004e2253426ff4423c..cfbd6fccf550301b37149c640ac4126a9a17dafc 100644 (file)
@@ -194,7 +194,7 @@ class Backend(object):
                        *args,
                        stdin=asyncio.subprocess.DEVNULL,
                        stdout=asyncio.subprocess.PIPE,
-                       stderr=asyncio.subprocess.STDOUT,
+                       stderr=asyncio.subprocess.PIPE,
                        **kwargs,
                )
 
@@ -218,8 +218,22 @@ class Backend(object):
                                stdout.append(line)
 
                # Wait until the process has finished
-               await process.wait()
+               returncode = await process.wait()
 
+               # Check the return code
+               if returncode:
+                       # Fetch any output from the standard error output
+                       stderr = await process.stderr.read()
+                       stderr = stderr.decode()
+
+                       # Log the error
+                       log.error("Error running command: %s (code=%s)" % (" ".join(args), returncode))
+                       if stderr:
+                               log.error(stderr)
+
+                       raise CommandExecutionError(returncode, stderr)
+
+               # Return output if requested
                if return_output:
                        return "\n".join(stdout)
 
index 944939f298499301b459a79c23b2bc27de9975ef..66314ea9e812efefb09a20447ea09aa0bb98a7da 100644 (file)
@@ -1,5 +1,14 @@
 
 
+class CommandExecutionError(Exception):
+       """
+               Raised when the executed command at Backend.command() returned an error
+       """
+       def __init__(self, returncode, stderr=None):
+               self.returncode = returncode
+               self.stderr = stderr
+
+
 class NoSuchDistroError(Exception):
        """
                Raised when a certain distribution could not be found