Skip to content

fix(io): tool_output falls back to ASCII on UnicodeEncodeError (#5029)#5031

Open
MukundaKatta wants to merge 1 commit intoAider-AI:mainfrom
MukundaKatta:fix/tool-output-unicode-fallback
Open

fix(io): tool_output falls back to ASCII on UnicodeEncodeError (#5029)#5031
MukundaKatta wants to merge 1 commit intoAider-AI:mainfrom
MukundaKatta:fix/tool-output-unicode-fallback

Conversation

@MukundaKatta
Copy link
Copy Markdown

Why

Closes #5029.

/map output on Windows with cp1251 (Russian) locale crashed with an uncaught UnicodeEncodeError. Root cause: Rich uses U+22EE (vertical ellipsis, ) for tree/box drawing, and the legacy Windows terminal's cp1251 codec can't encode it.

The crash traceback points at aider/io.py:1012 inside tool_output:

File "io.py", line 1012, in tool_output
    self.console.print(*messages, style=style)

What

_tool_message already handles this exact case (see current code lines 979–986): catch UnicodeEncodeError, re-encode with errors='replace', retry the print.

tool_output was missing the same handler. This PR mirrors the existing fallback into tool_output — same pattern, same semantics. No new public API, no behavior change on UTF-8 platforms.

Diff shape

  • aider/io.py: +14 lines (try/except in tool_output)
  • tests/basic/test_io.py: +26 lines (regression test)

Test

New test test_tool_output_unicode_fallback models the exact #5029 scenario — U+22EE message, first console.print raises UnicodeEncodeError, second succeeds with the character replaced.

$ pytest tests/basic/test_io.py -k unicode -v
test_autocompleter_with_unicode_file PASSED
test_tool_message_unicode_fallback PASSED
test_tool_output_unicode_fallback PASSED
3 passed

Scope

Deliberately narrow — just the crash in #5029. Broader robustness (forcing UTF-8 console mode on Windows, warning users, etc.) is a larger design discussion and not needed to close this issue.

…-AI#5029)

/map output on Windows cp1251 (and other non-UTF-8 code pages) crashed with
an uncaught UnicodeEncodeError because Rich uses U+22EE (vertical ellipsis)
for tree/box drawing — characters the legacy Windows terminal renderer
cannot encode via cp1251.

_tool_message already handled this via a try/except with ASCII replacement.
tool_output — which is what the Aider-AI#5029 traceback crashes on at line 1012 —
was missing the same handler.

This patch mirrors the existing _tool_message fallback into tool_output:
on UnicodeEncodeError, re-encode each message with errors='replace' and
retry the print.

Test: tests/basic/test_io.py::test_tool_output_unicode_fallback
(alongside the existing test_tool_message_unicode_fallback pattern).

Verified via pytest — both unicode-fallback tests pass.

Signed-off-by: Mukunda Katta <mukunda.vjcs6@gmail.com>
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

Uncaught UnicodeEncodeError in cp1251.py line 19

2 participants