From c4e4967691f0e89bc737aec06e307f47a951ed85 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 4 Sep 2024 08:56:34 -0700 Subject: [PATCH] refactor: improve error handling in run_cmd function --- aider/coders/base_coder.py | 2 +- aider/commands.py | 4 +++- aider/run_cmd.py | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index f39b720e7..86d45b718 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -1946,7 +1946,7 @@ class Coder: self.io.tool_output(f"Running {command}") # Add the command to input history self.io.add_to_input_history(f"/run {command.strip()}") - exit_status, output = run_cmd(command) + exit_status, output = run_cmd(command, error_print=self.io.tool_error) if output: accumulated_output += f"Output from {command}\n{output}\n" diff --git a/aider/commands.py b/aider/commands.py index 8cbc117cc..551de4373 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -778,7 +778,9 @@ class Commands: def cmd_run(self, args, add_on_nonzero_exit=False): "Run a shell command and optionally add the output to the chat (alias: !)" - exit_status, combined_output = run_cmd(args, verbose=self.verbose) + exit_status, combined_output = run_cmd( + args, verbose=self.verbose, error_print=self.io.tool_error + ) instructions = None if combined_output is None: diff --git a/aider/run_cmd.py b/aider/run_cmd.py index 51f8c08f5..2fd70a94c 100644 --- a/aider/run_cmd.py +++ b/aider/run_cmd.py @@ -14,7 +14,7 @@ def run_cmd(command, verbose=False, error_print=None): return run_cmd_subprocess(command, verbose) except OSError as e: - error_message = f"OSError occurred while running command '{command}': {str(e)}" + error_message = f"Error occurred while running command '{command}': {str(e)}" if error_print is None: print(error_message) else: