Skip to content

fix: handle UnicodeDecodeError when reading .aider_ignore file (issue #5276)#5380

Open
chrislazar25 wants to merge 1 commit into
Aider-AI:mainfrom
chrislazar25:fix/issue-5276
Open

fix: handle UnicodeDecodeError when reading .aider_ignore file (issue #5276)#5380
chrislazar25 wants to merge 1 commit into
Aider-AI:mainfrom
chrislazar25:fix/issue-5276

Conversation

@chrislazar25

@chrislazar25 chrislazar25 commented Jul 1, 2026

Copy link
Copy Markdown

Summary

Fix UnicodeDecodeError when reading .aider_ignore on Windows with non-UTF-8 system locales.

Technical Details

Root Cause: repo.py:517 calls Path.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_ignore file contains UTF-8 bytes un-decodable by the active codepage, UnicodeDecodeError is 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 the read_text() call, explicitly decoding as UTF-8 and replacing any undecodable bytes with the replacement character rather than crashing.

Verification

  • Confirmed adherence to CONTRIBUTING.md
  • Ran python3 -m pytest tests/basic/test_repo.py — 21/21 passed
  • Ran python3 -m pytest tests/basic/ — 455/455 non-voice tests passed (1 pre-existing PortAudio skip, 1 pre-existing PortAudio failure)
  • Pre-commit hooks passed (isort, black, flake8, codespell)

Blast Radius

  • Impact: Medium — crashes hard on startup for affected Windows configurations. Zero impact on Linux/macOS where default encoding is already UTF-8.
  • Trade-offs: None. 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

…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.).
@chrislazar25 chrislazar25 marked this pull request as ready for review July 1, 2026 21:23
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 UnicodeDecodeError in pathlib.py line 1028

1 participant