Skip to content
Commits on Source (3)
......@@ -437,16 +437,18 @@ class File(object, metaclass=abc.ABCMeta):
)
except subprocess.CalledProcessError as e:
difference = self.compare_bytes(other, source=source)
if e.output:
output = re.sub(r'^', ' ', e.output, flags=re.MULTILINE)
else:
output = '<none>'
cmd = ' '.join(e.cmd)
if difference is None:
return None
output = '<none>'
if e.output:
output = '\n{}'.format(
re.sub(r'^', ' ', e.output, flags=re.MULTILINE)
)
difference.add_comment(
"Command `%s` exited with %d. Output:\n%s"
% (cmd, e.returncode, output)
"Command `{}` exited with return code {}. Output: {}".format(
cmd, e.returncode, output
)
)
except RequiredToolNotFound as e:
difference = self.compare_bytes(other, source=source)
......
......@@ -92,8 +92,17 @@ def from_command(command):
end_nl = feeder(out_file)
returncode = command.returncode
if returncode not in (0, -signal.SIGTERM):
# On error, default to displaying all lines of standard output.
output = command.stderr
if not output and command.stdout:
# ... but if we don't have, return the first line of the
# standard output.
output = '{}{}'.format(
command.stdout[0].decode('utf-8', 'ignore').strip(),
'\n[…]' if len(command.stdout) > 1 else '',
)
raise subprocess.CalledProcessError(
returncode, command.cmdline(), output=command.stderr
returncode, command.cmdline(), output=output
)
return end_nl
......