From 95850a7a5e5a77f6543cdc8d8ee8265ad021489a Mon Sep 17 00:00:00 2001 From: scheibelp Date: Wed, 19 Sep 2018 17:29:15 -0700 Subject: report error if failed process captures stderr (#9293) When a Spack Executable was configured to capture stderr and the process failed, the error messages of the process were discarded. This made it difficult to understand why the process failed. The exception is now updated to include the stderr of the process when the Executable captures stderr. --- lib/spack/spack/util/executable.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/util/executable.py b/lib/spack/spack/util/executable.py index 1817d0a77b..e64845f0ef 100644 --- a/lib/spack/spack/util/executable.py +++ b/lib/spack/spack/util/executable.py @@ -186,18 +186,28 @@ class Executable(object): env=env) out, err = proc.communicate() - rc = self.returncode = proc.returncode - if fail_on_error and rc != 0 and (rc not in ignore_errors): - raise ProcessError('Command exited with status %d:' % - proc.returncode, cmd_line) - + result = None if output is str or error is str: result = '' if output is str: result += to_str(out) if error is str: result += to_str(err) - return result + + rc = self.returncode = proc.returncode + if fail_on_error and rc != 0 and (rc not in ignore_errors): + long_msg = cmd_line + if result: + # If the output is not captured in the result, it will have + # been stored either in the specified files (e.g. if + # 'output' specifies a file) or written to the parent's + # stdout/stderr (e.g. if 'output' is not specified) + long_msg += '\n' + result + + raise ProcessError('Command exited with status %d:' % + proc.returncode, long_msg) + + return result except OSError as e: raise ProcessError( -- cgit v1.2.3-70-g09d2