bugfix: Executable should record return code on CalledProcessError

Spack's `Executable` class isn't properly returning a called process's
return code when it fails with a `CalledProcessError`.  Record it before
raising a `ProcessError` so that client code can query it later.

Signed-off-by: Todd Gamblin <tgamblin@llnl.gov>
This commit is contained in:
Todd Gamblin 2025-05-19 16:22:56 -07:00
parent be57175413
commit 52ce977b93
No known key found for this signature in database
GPG Key ID: C16729F1AACF66C6

View File

@ -295,11 +295,11 @@ def streamify(arg, mode):
raise ProcessError("%s: %s" % (self.exe[0], e.strerror), message)
except subprocess.CalledProcessError as e:
self.returncode = e.returncode
if fail_on_error:
raise ProcessError(
str(e),
"\nExit status %d when invoking command: %s"
% (proc.returncode, cmd_line_string),
f"\nExit status {e.returncode} when invoking command: {cmd_line_string}",
)
except subprocess.TimeoutExpired as te:
proc.kill()