fix: Improve error handling in run_interactive_command_pexpect

This commit is contained in:
Paul Gauthier 2024-08-27 09:09:24 -07:00 committed by Paul Gauthier (aider)
parent 46ce049777
commit ec935842ab

View file

@ -17,11 +17,11 @@ IMAGE_EXTENSIONS = {".png", ".jpg", ".jpeg", ".gif", ".bmp", ".tiff", ".webp"}
def run_interactive_command(command): def run_interactive_command(command):
try: try:
import pexpect import pexpect
return run_interactive_command_pexpect(command)
except ImportError: except ImportError:
return run_interactive_command_subprocess(command) return run_interactive_command_subprocess(command)
return run_interactive_command_pexpect(command)
def run_interactive_command_subprocess(command): def run_interactive_command_subprocess(command):
try: try:
@ -46,6 +46,8 @@ def run_interactive_command_pexpect(command):
:param command: The command to run as a string. :param command: The command to run as a string.
:return: A tuple containing (exit_status, output) :return: A tuple containing (exit_status, output)
""" """
import pexpect
output = BytesIO() output = BytesIO()
def output_callback(b): def output_callback(b):
@ -70,7 +72,6 @@ def run_interactive_command_pexpect(command):
except pexpect.ExceptionPexpect as e: except pexpect.ExceptionPexpect as e:
error_msg = f"Error running command: {e}" error_msg = f"Error running command: {e}"
print(error_msg, file=sys.stderr)
return 1, error_msg return 1, error_msg