Skip to content

Commit 1b344b3

Browse files
committed
Update call_quietly to show output on failure
If 'call_quietly' fails, there is no indication as to what the failure was, except for the exit/status code from the subprocess. This adds a new exception type that will print out stdout/stderr from the subprocess
1 parent 7f7758b commit 1b344b3

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

utils/update_checkout/tests/scheme_mock.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,25 @@
6363
}
6464

6565

66+
class CallQuietlyException(Exception):
67+
def __init__(self, command, returncode, output):
68+
self.command = command
69+
self.returncode = returncode
70+
self.output = output
71+
72+
def __str__(self):
73+
return f"Command returned a non-zero exit status {self.returncode}:\n"\
74+
f"Command: {' '.join(self.command)}\n" \
75+
f"Output: {self.output.decode('utf-8')}"
76+
77+
6678
def call_quietly(*args, **kwargs):
67-
with open(os.devnull, 'w') as f:
68-
kwargs['stdout'] = f
69-
kwargs['stderr'] = f
70-
subprocess.check_call(*args, **kwargs)
79+
kwargs['stderr'] = subprocess.STDOUT
80+
try:
81+
subprocess.check_output(*args, **kwargs)
82+
except subprocess.CalledProcessError as e:
83+
raise CallQuietlyException(command=e.cmd, returncode=e.returncode,
84+
output=e.stdout) from e
7185

7286

7387
def create_dir(d):

0 commit comments

Comments
 (0)