Repository navigation
Conversation
…TF-8 initialize_gitignore() and the AGENTS.md/CLAUDE.md helpers used Path.read_text()/write_text() without an encoding, so they used the locale encoding. On Windows with a non-UTF-8 code page this made `reflex init` crash: the canonical AGENTS.md contains an em dash, which cp932 cannot encode, and existing UTF-8 files with CJK text could not be decoded. On cp1252 the files were silently written in the ANSI code page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
1 issue found across 3 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="reflex/utils/frontend_skeleton.py">
<violation number="1" location="reflex/utils/frontend_skeleton.py:37">
P2: Strict UTF-8 decoding of an existing .gitignore now makes `reflex init` crash on legacy non-UTF-8 files that previously loaded fine. Consider catching UnicodeDecodeError here and reporting a clear warning or error that names the file, instead of letting the exception abort init.</violation>
</file>
Reply to a comment to ask cubic a question or push back. It learns from your replies.
View guided diff | Re-trigger cubic
| if gitignore_file.exists(): | ||
| current_ignore = [ln.strip() for ln in gitignore_file.read_text().splitlines()] | ||
| current_ignore = [ | ||
| ln.strip() for ln in gitignore_file.read_text(encoding="utf-8").splitlines() |
There was a problem hiding this comment.
P2: Strict UTF-8 decoding of an existing .gitignore now makes reflex init crash on legacy non-UTF-8 files that previously loaded fine. Consider catching UnicodeDecodeError here and reporting a clear warning or error that names the file, instead of letting the exception abort init.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At reflex/utils/frontend_skeleton.py, line 37:
<comment>Strict UTF-8 decoding of an existing .gitignore now makes `reflex init` crash on legacy non-UTF-8 files that previously loaded fine. Consider catching UnicodeDecodeError here and reporting a clear warning or error that names the file, instead of letting the exception abort init.</comment>
<file context>
@@ -33,7 +33,9 @@ def initialize_gitignore(
if gitignore_file.exists():
- current_ignore = [ln.strip() for ln in gitignore_file.read_text().splitlines()]
+ current_ignore = [
+ ln.strip() for ln in gitignore_file.read_text(encoding="utf-8").splitlines()
+ ]
</file context>
[Low impact] The change is limited to files created or updated during project setup. Add a fallback for existing locale-encoded files before merging. Findings
Summary
Reviews (1) · Last reviewed commit: "Read and write reflex init's AGENTS.md, ..." · Reviewed by Greptile |
| if gitignore_file.exists(): | ||
| current_ignore = [ln.strip() for ln in gitignore_file.read_text().splitlines()] | ||
| current_ignore = [ | ||
| ln.strip() for ln in gitignore_file.read_text(encoding="utf-8").splitlines() |
There was a problem hiding this comment.
Existing files stop initialization
If an existing .gitignore contains café/ saved as cp1252, this UTF-8 read raises an uncaught UnicodeDecodeError and stops reflex init. Earlier Reflex versions could read and write that file using the Windows locale. The same change affects existing AGENTS.md and CLAUDE.md files.
Keep UTF-8 for writes, but add a fallback for legacy reads and a regression test.
All Submissions:
Type of change
Changes To Core Features:
What and why
reflex initwrites the managed AGENTS.md section and the CLAUDE.md bridge, and merges.gitignore. It does this withPath.read_text()/write_text()and no encoding, so on Windows these files use the ANSI code page.On Japanese Windows (cp932) with Python 3.11, a plain
reflex initstops here:The canonical AGENTS.md contains an em dash. If an AGENTS.md, CLAUDE.md or
.gitignorealready has CJK text, the run fails withUnicodeDecodeErrorinstead. On cp1252 the em dash can be encoded, so there is no error, but the file is saved as cp1252 instead of UTF-8.This change passes
encoding="utf-8"to those reads and writes, aspath_ops.write_fileand #6761 (reflex rename) already do. No other files are touched. Python 3.15 turns on UTF-8 mode by default, but 3.11 to 3.14 still use the locale encoding.Tests: three new unit tests in
tests/units/utils/test_utils.pyuse non-ASCII content. With cp932 they fail without the fix (UnicodeEncodeError/UnicodeDecodeError) and pass with it. Their strings can't be encoded or decoded as cp1252 either, so they would fail on the Windows CI runners without the fix. A towncrier fragment is innews/.I used Claude Code to write this change.