Skip to content

Conversation

@ThanhNguyxn
Copy link

Summary

Fixes #3844

Emoji characters pasted from Windows clipboard can contain invalid surrogate pairs that cause UnicodeEncodeError: 'utf-8' codec can't encode characters ... surrogates not allowed when printing to the console in verbose mode (-v).

Root Cause

In utils.py line 139, print(formatted_output) directly prints the message content. When the content contains surrogate characters from emoji input, Python's print() fails with UnicodeEncodeError.

Fix

Added try/except around print() in show_messages() to catch UnicodeEncodeError and fall back to encoding with surrogatepass error handler, then decoding with replace to substitute problematic characters:

try:
    print(formatted_output)
except UnicodeEncodeError:
    safe_output = formatted_output.encode("utf-8", errors="surrogatepass").decode(
        "utf-8", errors="replace"
    )
    print(safe_output)

This prevents the crash while still displaying readable output.

Fixes Aider-AI#3844

Emoji characters pasted from Windows clipboard can contain invalid
surrogate pairs that cause UnicodeEncodeError when printing to
the console in verbose mode (-v).

Added try/except around print() to catch UnicodeEncodeError and
fall back to encoding with surrogatepass before printing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Emoji input causes display issues and a crash (UnicodeEncodeError) on Windows Terminal

1 participant