Skip to content

Fix check_ai.py crashing on Windows when guides are UTF-8 - #14846

Closed
tanvir-ux wants to merge 1 commit into
huggingface:mainfrom
tanvir-ux:fix/check-ai-utf8-read
Closed

tanvir-ux wants to merge 1 commit into
huggingface:mainfrom
tanvir-ux:fix/check-ai-utf8-read

Conversation

@tanvir-ux

Copy link
Copy Markdown

Fixes #14837

What was broken

python utils/check_ai.py crashes on Windows when the default locale encoding is not UTF-8 (typical for a redirected/non-console stdout path — ANSI code page like cp1252). The three Path.read_text() calls in utils/check_ai.py inherited that locale, so any guide with curly quotes / other non-cp1252 bytes blew up with UnicodeDecodeError.

Fix

Pass encoding="utf-8" on all three reads. Repo Markdown is UTF-8; the check should not depend on the machine locale.

How I tested

PYTHONPATH=src:utils python -m pytest tests/others/test_check_ai.py -q
# 1 passed

The regression builds a tiny .ai/ tree with U+201C curly quotes and monkeypatches Path.read_text so a missing encoding falls back to cp1252 — same failure mode as the issue. With the pin, main() returns 0.

On Windows, Path.read_text() without encoding uses the ANSI code page
(e.g. cp1252), so UTF-8 guides with curly quotes crash the agent setup
check. Pin encoding="utf-8" on all three reads and add a regression that
simulates a cp1252 default.

Fixes huggingface#14837
@github-actions github-actions Bot added fixes-issue size/M PR with diff < 200 LOC tests labels Sep 23, 2026
@tanvir-ux

Copy link
Copy Markdown
Author

Closing this to keep my open PRs manageable. Happy to reopen and rebase if maintainers want it.

@tanvir-ux tanvir-ux closed this Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fixes-issue size/M PR with diff < 200 LOC tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows: check_ai.py fails decoding UTF-8 guides with the default locale

1 participant