已开启
[Bug] validate_template.py 在 cp1252 输出环境下因中文结果触发 UnicodeEncodeError #170
hid63709861创建于  22 小时前
hid63709861
hid63709861
22 小时前 创建

问题

在 Windows 上,当 Python 标准输出为 cp1252(例如默认重定向输出的环境)时,README 中的模板自检命令在输出中文检查结果时崩溃,不能展示检查总结。

复现环境

  • Windows,Python 3.8.6
  • 仓库 main,提交 b0053343536efeb056c8d8a41f39acc67743ba3b
  • sys.stdout.encoding 为 cp1252;在仓库根目录 scenario-planner 运行
set PYTHONIOENCODING=cp1252
python scripts/validate_template.py

实际结果

退出码 1,错误位于 scripts/validate_template.py 第 271 行的 print(...):

UnicodeEncodeError: 'charmap' codec can't encode characters in position 28-33: character maps to <undefined>

对照与预期

同一份仓库运行 python -X utf8 scripts/validate_template.py 输出 7 PASS / 0 WARN / 0 FAIL,说明本次不是模板检查失败。期望在非 UTF-8 的 stdout 环境下也能正常显示结果并返回与检查结果一致的退出码,或者提供清楚的编码提示及 README 的解决方法。可考虑为重定向输出提供 UTF-8 配置说明,并增加非 UTF-8 stdout 的回归测试。

likedislike