From 893ed0fbbf1682a416225fccbd35c3db5e034f56 Mon Sep 17 00:00:00 2001 From: Paul Cristian Sarbu Date: Thu, 27 Feb 2025 18:06:29 +0100 Subject: just-lock: Allow stderr capture and reporting when running commands --- bin/just-lock.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'bin/just-lock.py') diff --git a/bin/just-lock.py b/bin/just-lock.py index ae78c756..01fbdd3b 100755 --- a/bin/just-lock.py +++ b/bin/just-lock.py @@ -156,7 +156,8 @@ def run_cmd( cmd: List[str], *, env: Optional[Any] = None, - stdout: Optional[Any] = subprocess.DEVNULL, + stdout: Optional[Any] = subprocess.DEVNULL, # ignore output by default + stderr: Optional[Any] = subprocess.PIPE, # capture errors by default stdin: Optional[Any] = None, input: Optional[bytes] = None, cwd: str, @@ -172,14 +173,16 @@ def run_cmd( cwd=cwd, env=env, stdout=stdout, + stderr=stderr, stdin=stdin, input=input) if result.returncode == 0: return result.stdout, result.returncode # return successful result if fail_context is not None: - fail("%sCommand %s in %s failed after %d attempt%s" % - (fail_context, cmd, cwd, attempts, "" if attempts == 1 else "s")) - return result.stdout, result.returncode # return result of last failure + fail("%sCommand %s in %s failed after %d attempt%s with:\n%s" % + (fail_context, cmd, cwd, attempts, "" if attempts == 1 else "s", + result.stderr)) + return result.stderr, result.returncode # return result of last failure def try_rmtree(tree: str) -> None: -- cgit v1.2.3