Skip to content

Commit

Permalink
feat: add error handling and flexible error reporting to run_cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-gauthier committed Sep 4, 2024
1 parent db75900 commit d8639ba
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions aider/run_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@
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)

return run_cmd_subprocess(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)
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):
Expand Down

0 comments on commit d8639ba

Please sign in to comment.