From f66136fcc26013ddbae95e8c6d6be21e0985e0af Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Wed, 8 Mar 2023 17:50:11 -0800 Subject: [PATCH] zulip_tools: Improve error for `run` subprocess killed by signal. Signed-off-by: Anders Kaseorg --- scripts/lib/zulip_tools.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/scripts/lib/zulip_tools.py b/scripts/lib/zulip_tools.py index a2a01eae00..70936cec04 100755 --- a/scripts/lib/zulip_tools.py +++ b/scripts/lib/zulip_tools.py @@ -12,6 +12,7 @@ import random import re import shlex import shutil +import signal import subprocess import sys import time @@ -236,12 +237,25 @@ def run(args: Sequence[str], **kwargs: Any) -> None: try: subprocess.check_call(args, **kwargs) - except subprocess.CalledProcessError: + except subprocess.CalledProcessError as error: print() - print( - WHITEONRED + f"Error running a subcommand of {sys.argv[0]}: {shlex.join(args)}" + ENDC - ) - print(WHITEONRED + "Actual error output for the subcommand is just above this." + ENDC) + if error.returncode < 0: + try: + signal_name = signal.Signals(-error.returncode).name + except ValueError: + signal_name = f"unknown signal {-error.returncode}" + print( + WHITEONRED + + f"Subcommand of {sys.argv[0]} died with {signal_name}: {shlex.join(args)}" + + ENDC + ) + else: + print( + WHITEONRED + + f"Subcommand of {sys.argv[0]} failed with exit status {error.returncode}: {shlex.join(args)}" + + ENDC + ) + print(WHITEONRED + "Actual error output for the subcommand is just above this." + ENDC) print() sys.exit(1)