Fix GBK decode crashes on Windows by forcing UTF-8 everywhere#453
Open
Holmescalvin wants to merge 1 commit into
Open
Fix GBK decode crashes on Windows by forcing UTF-8 everywhere#453Holmescalvin wants to merge 1 commit into
Holmescalvin wants to merge 1 commit into
Conversation
subprocess.run(text=True) and Path.read_text()/write_text() without an explicit encoding fall back to the OS default, which is GBK on Chinese Windows. Reading/writing the project's UTF-8 files (or subprocess output containing non-ASCII bytes) then crashes with UnicodeDecodeError. Force encoding="utf-8" everywhere, with errors="replace" on subprocess capture so unexpected bytes degrade gracefully instead of killing the process.
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
subprocess.run(text=True)andPath.read_text()/write_text()without an explicitencodingfall back to the OS default codec, which is GBK on Chinese Windows.UnicodeDecodeError— e.g. runnings10_system_prompt/code.pyand readingREADME.mdfails immediately.encoding="utf-8"on everyread_text/write_textcall, and addsencoding="utf-8", errors="replace"to everysubprocess.run(..., text=True, ...)call across the tutorialcode.pyfiles,agents/*.py, and theagent-builderskill scripts, so output stays readable instead of crashing the process even if a command emits unexpected bytes.Test plan
python -m py_compileon every changed file — all compile cleanlys10_system_prompt/code.pyend-to-end on Windows (Chinese locale/GBK) after the fix — starts and readsREADME.md/memory files without crashingUnicodeDecodeError/TypeError: unsupported operand type(s) for +: 'NoneType' and 'str') to confirm root cause🤖 Generated with Claude Code