From 52ce977b93c382aafbaec6844484586468d1d380 Mon Sep 17 00:00:00 2001 From: Todd Gamblin Date: Mon, 19 May 2025 16:22:56 -0700 Subject: [PATCH] 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 --- lib/spack/spack/util/executable.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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()