From d8639bac48d4706f4e45da2547c944aba867788f Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Wed, 4 Sep 2024 08:54:30 -0700 Subject: [PATCH] feat: add error handling and flexible error reporting to run_cmd --- aider/run_cmd.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/aider/run_cmd.py b/aider/run_cmd.py index 3c64fd548..51f8c08f5 100644 --- a/aider/run_cmd.py +++ b/aider/run_cmd.py @@ -7,11 +7,19 @@ from io import BytesIO import pexpect -def run_cmd(command, verbose=False): - if sys.stdin.isatty() and hasattr(pexpect, "spawn") and platform.system() != "Windows": - return run_cmd_pexpect(command, verbose) +def run_cmd(command, verbose=False, error_print=None): + try: + if sys.stdin.isatty() and hasattr(pexpect, "spawn") and platform.system() != "Windows": + return run_cmd_pexpect(command, verbose) - return run_cmd_subprocess(command, verbose) + return run_cmd_subprocess(command, verbose) + except OSError as e: + error_message = f"OSError occurred while running command '{command}': {str(e)}" + if error_print is None: + print(error_message) + else: + error_print(error_message) + return 1, error_message def run_cmd_subprocess(command, verbose=False):