mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-04 03:35:00 +00:00
refactor: improve error handling in run_cmd function
This commit is contained in:
parent
d8639bac48
commit
c4e4967691
3 changed files with 5 additions and 3 deletions
|
@ -1946,7 +1946,7 @@ class Coder:
|
||||||
self.io.tool_output(f"Running {command}")
|
self.io.tool_output(f"Running {command}")
|
||||||
# Add the command to input history
|
# Add the command to input history
|
||||||
self.io.add_to_input_history(f"/run {command.strip()}")
|
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:
|
if output:
|
||||||
accumulated_output += f"Output from {command}\n{output}\n"
|
accumulated_output += f"Output from {command}\n{output}\n"
|
||||||
|
|
||||||
|
|
|
@ -778,7 +778,9 @@ class Commands:
|
||||||
|
|
||||||
def cmd_run(self, args, add_on_nonzero_exit=False):
|
def cmd_run(self, args, add_on_nonzero_exit=False):
|
||||||
"Run a shell command and optionally add the output to the chat (alias: !)"
|
"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
|
instructions = None
|
||||||
|
|
||||||
if combined_output is None:
|
if combined_output is None:
|
||||||
|
|
|
@ -14,7 +14,7 @@ def run_cmd(command, verbose=False, error_print=None):
|
||||||
|
|
||||||
return run_cmd_subprocess(command, verbose)
|
return run_cmd_subprocess(command, verbose)
|
||||||
except OSError as e:
|
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:
|
if error_print is None:
|
||||||
print(error_message)
|
print(error_message)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue