Skip to content

Commit

Permalink
refactor: improve error handling in run_cmd function
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-gauthier committed Sep 4, 2024
1 parent d8639ba commit c4e4967
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion aider/coders/base_coder.py
Original file line number Diff line number Diff line change
Expand Up @@ -1946,7 +1946,7 @@ def handle_shell_commands(self, commands_str, group):
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"

Expand Down
4 changes: 3 additions & 1 deletion aider/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,9 @@ def cmd_test(self, args):

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:
Expand Down
2 changes: 1 addition & 1 deletion aider/run_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit c4e4967

Please sign in to comment.