Improved error handling in Aider to safely encode and decode text containing emojis or other problematic characters.

This commit is contained in:
Paul Gauthier (aider) 2024-07-23 11:39:31 +02:00
parent 1a345a4036
commit 9a7c67966a

View file

@ -1233,7 +1233,12 @@ class Coder:
if self.show_pretty():
self.live_incremental_response(False)
elif text:
sys.stdout.write(text)
try:
sys.stdout.write(text)
except UnicodeEncodeError:
# Safely encode and decode the text
safe_text = text.encode(sys.stdout.encoding, errors='backslashreplace').decode(sys.stdout.encoding)
sys.stdout.write(safe_text)
sys.stdout.flush()
yield text