*args,
stdin=asyncio.subprocess.DEVNULL,
stdout=asyncio.subprocess.PIPE,
- stderr=asyncio.subprocess.STDOUT,
+ stderr=asyncio.subprocess.PIPE,
**kwargs,
)
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)
+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