Skip to content

Fix GBK decode crashes on Windows by forcing UTF-8 everywhere#453

Open
Holmescalvin wants to merge 1 commit into
shareAI-lab:mainfrom
Holmescalvin:fix/gbk-utf8-encoding-crash
Open

Fix GBK decode crashes on Windows by forcing UTF-8 everywhere#453
Holmescalvin wants to merge 1 commit into
shareAI-lab:mainfrom
Holmescalvin:fix/gbk-utf8-encoding-crash

Conversation

@Holmescalvin

Copy link
Copy Markdown

Summary

  • subprocess.run(text=True) and Path.read_text()/write_text() without an explicit encoding fall back to the OS default codec, which is GBK on Chinese Windows.
  • Reading/writing this project's UTF-8 source/data files (or capturing subprocess output containing non-ASCII bytes) then crashes with UnicodeDecodeError — e.g. running s10_system_prompt/code.py and reading README.md fails immediately.
  • Forces encoding="utf-8" on every read_text/write_text call, and adds encoding="utf-8", errors="replace" to every subprocess.run(..., text=True, ...) call across the tutorial code.py files, agents/*.py, and the agent-builder skill scripts, so output stays readable instead of crashing the process even if a command emits unexpected bytes.

Test plan

  • python -m py_compile on every changed file — all compile cleanly
  • Ran s10_system_prompt/code.py end-to-end on Windows (Chinese locale/GBK) after the fix — starts and reads README.md/memory files without crashing
  • Reproduced the original crash before the fix (UnicodeDecodeError / TypeError: unsupported operand type(s) for +: 'NoneType' and 'str') to confirm root cause

🤖 Generated with Claude Code

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.
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.

1 participant