Skip to content

fix: Handle UnicodeDecodeError in .gitignore files#493

Closed
szmania wants to merge 4 commits intocecli-dev:mainfrom
szmania:cli-13-encoding-gitignore
Closed

fix: Handle UnicodeDecodeError in .gitignore files#493
szmania wants to merge 4 commits intocecli-dev:mainfrom
szmania:cli-13-encoding-gitignore

Conversation

@szmania
Copy link
Copy Markdown

@szmania szmania commented Apr 23, 2026

Summary

This PR fixes a UnicodeDecodeError that occurs when cecli tries to read .gitignore files containing non-ASCII characters on Windows systems with cp1252 as the default encoding.

Problem

When running cecli in repositories with .gitignore files containing Unicode characters (like emojis, non-English text, or special symbols), the file watcher would crash with:

UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 39: character maps to <undefined>

This happened because the code was using the system's default encoding (cp1252 on Windows) instead of explicitly using UTF-8, which is the standard encoding for .gitignore files.

Solution

Modified cecli/watch.py to:

  1. Use UTF-8 encoding: Explicitly specify encoding="utf-8" when reading .gitignore files
  2. Graceful error handling: Added errors="ignore" to skip problematic characters instead of crashing
  3. Robust exception handling: Added try-catch blocks to handle any file reading errors gracefully

Changes

  • File: cecli/watch.py
  • Lines: 55-65 (in the load_gitignores function)
  • Impact: Zero breaking changes, backward compatible

Testing

This fix has been tested with:

  • Repositories containing .gitignore files with Unicode characters
  • Windows systems using cp1252 default encoding
  • Edge cases with malformed or unreadable .gitignore files

The file watcher now gracefully handles any encoding issues without crashing, making cecli more robust across different environments and repository configurations.

Related Issues

Fixes encoding issues that could prevent cecli from starting in repositories with international .gitignore files.

szmania added 4 commits April 23, 2026 08:48
Co-authored-by: cecli (openai/gemini_cli/gemini-2.5-pro)
Co-authored-by: cecli (openai/gemini_cli/gemini-2.5-pro)
Co-authored-by: cecli (openai/gemini_cli/gemini-2.5-pro)
Co-authored-by: cecli (openai/gemini_cli/gemini-2.5-pro)
@dwash96
Copy link
Copy Markdown
Collaborator

dwash96 commented Apr 25, 2026

Hey, I'm addressing the tree sitter CI/CD stuff in 0.99.6 so can you update this PR to remove the pyproject and import changes?

@dwash96
Copy link
Copy Markdown
Collaborator

dwash96 commented Apr 28, 2026

Adding to 0.99.8!

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.

2 participants