From e3d7793088c9b1afd488afa5932b897cfed6ba6f Mon Sep 17 00:00:00 2001 From: VAN BOSSUYT Nicolas Date: Sat, 18 Feb 2023 20:58:58 +0100 Subject: [PATCH] Display command name next to exec/popen exception --- osdk/shell.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/osdk/shell.py b/osdk/shell.py index 7473423..4f2255c 100644 --- a/osdk/shell.py +++ b/osdk/shell.py @@ -123,16 +123,17 @@ def exec(*args: str): proc = subprocess.run(args) except FileNotFoundError: - raise Exception(f"Command not found") + raise Exception(f"{args[0]}: Command not found") except KeyboardInterrupt: - raise Exception("Interrupted") + raise Exception(f"{args[0]}: Interrupted") if proc.returncode == -signal.SIGSEGV: - raise Exception("Segmentation fault") + raise Exception(f"{args[0]}: Segmentation fault") if proc.returncode != 0: - raise Exception(f"Process exited with code {proc.returncode}") + raise Exception( + f"{args[0]}: Process exited with code {proc.returncode}") return True @@ -143,13 +144,14 @@ def popen(*args: str) -> str: try: proc = subprocess.run(args, stdout=subprocess.PIPE, stderr=sys.stderr) except FileNotFoundError: - raise Exception(f"Command not found") + raise Exception(f"{args[0]}: Command not found") if proc.returncode == -signal.SIGSEGV: - raise Exception("Segmentation fault") + raise Exception(f"{args[0]}: Segmentation fault") if proc.returncode != 0: - raise Exception(f"Process exited with code {proc.returncode}") + raise Exception( + f"{args[0]}: Process exited with code {proc.returncode}") return proc.stdout.decode('utf-8')