fix(io): tool_output falls back to ASCII on UnicodeEncodeError (#5029)#5031
Open
MukundaKatta wants to merge 1 commit intoAider-AI:mainfrom
Open
fix(io): tool_output falls back to ASCII on UnicodeEncodeError (#5029)#5031MukundaKatta wants to merge 1 commit intoAider-AI:mainfrom
MukundaKatta wants to merge 1 commit intoAider-AI:mainfrom
Conversation
…-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>
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Closes #5029.
/mapoutput on Windows with cp1251 (Russian) locale crashed with an uncaughtUnicodeEncodeError. 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:1012insidetool_output:What
_tool_messagealready handles this exact case (see current code lines 979–986): catchUnicodeEncodeError, re-encode witherrors='replace', retry the print.tool_outputwas missing the same handler. This PR mirrors the existing fallback intotool_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 intool_output)tests/basic/test_io.py: +26 lines (regression test)Test
New test
test_tool_output_unicode_fallbackmodels the exact #5029 scenario — U+22EE message, firstconsole.printraisesUnicodeEncodeError, second succeeds with the character replaced.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.