From 424f8f66d0b93946a4bd215727e722173d2263f3 Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Sun, 2 Jun 2024 21:56:49 +0200 Subject: fix: handle a failure to run hut subprocess well Print the return and stderr of the failed subprocess. --- import_issues.py | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/import_issues.py b/import_issues.py index c0910ae..93c4128 100755 --- a/import_issues.py +++ b/import_issues.py @@ -171,7 +171,7 @@ def get_labels(tracker: str) -> list[dict[str, str]]: ) except subprocess.CalledProcessError as ex: raise RuntimeError( - f"hut failed with excitcode {ex.returncode} and stderr:\n{ex.stderr}" + f"hut failed with excitcode {ex.returncode}\n\nstdout:\n{ex.stdout}\n\nand stderr:\n{ex.stderr}" ) from ex data = json.loads(ret.stdout) return data["me"]["tracker"]["labels"]["results"] @@ -271,23 +271,28 @@ def run_hut(cmds, tracker, msg, args=None, delay=None): ) if args is None: args = [] - if msg is None: - res = subprocess.run( - ["hut", "todo"] + cmds + ["-t", tracker] + args, - check=True, - encoding="utf-8", - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - ) - else: - res = subprocess.run( - ["hut", "todo"] + cmds + ["-t", tracker, "--stdin"] + args, - check=True, - encoding="utf-8", - input=msg, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - ) + try: + if msg is None: + res = subprocess.run( + ["hut", "todo"] + cmds + ["-t", tracker] + args, + check=True, + encoding="utf-8", + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) + else: + res = subprocess.run( + ["hut", "todo"] + cmds + ["-t", tracker, "--stdin"] + args, + check=True, + encoding="utf-8", + input=msg, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) + except subprocess.CalledProcessError as ex: + raise RuntimeError( + f"hut failed with excitcode {ex.returncode}\n\nstdout:\n{ex.stdout}\n\nand stderr:\n{ex.stderr}" + ) from ex time.sleep(delay) -- cgit