fix: handle UnicodeDecodeError when reading .aider_ignore file (issue #5276)#5380
Open
chrislazar25 wants to merge 1 commit into
Open
fix: handle UnicodeDecodeError when reading .aider_ignore file (issue #5276)#5380chrislazar25 wants to merge 1 commit into
chrislazar25 wants to merge 1 commit into
Conversation
…ider-AI#5276) Explicitly use encoding='utf-8' with errors='replace' instead of relying on system default encoding, which varies by locale and crashes on Windows with non-UTF-8 codepages (cp949, cp1252, gbk, etc.).
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.
Summary
Fix
UnicodeDecodeErrorwhen reading.aider_ignoreon Windows with non-UTF-8 system locales.Technical Details
Root Cause:
repo.py:517callsPath.read_text()without specifying an encoding. Python falls back to the system default encoding (cp949 on Korean Windows, cp1252 on Western EU, gbk on Chinese). When the.aider_ignorefile contains UTF-8 bytes un-decodable by the active codepage,UnicodeDecodeErroris raised.Mechanism: The crash propagates from
refresh_aider_ignore()→ignored_file()→get_tracked_files()→base_coder.py:get_addable_relative_files(), preventing aider from starting or adding files on affected systems.The patch adds
encoding='utf-8', errors='replace'to theread_text()call, explicitly decoding as UTF-8 and replacing any undecodable bytes with the replacement character rather than crashing.Verification
python3 -m pytest tests/basic/test_repo.py— 21/21 passedpython3 -m pytest tests/basic/— 455/455 non-voice tests passed (1 pre-existing PortAudio skip, 1 pre-existing PortAudio failure)Blast Radius
errors='replace'is already the established pattern in aider's I/O layer (io.py L493, L566, L1131). Worst case: an undecodable byte becomes U+FFFD in a gitignore pattern name, which is effectively non-existent in real usage.Closes #5276