diff --git a/lib/spack/spack/util/executable.py b/lib/spack/spack/util/executable.py index a8b34437493..064874f09cb 100644 --- a/lib/spack/spack/util/executable.py +++ b/lib/spack/spack/util/executable.py @@ -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()