Skip to content

fix: config_manager 读取 config.json 时自动检测编码#226

Merged
69gg merged 2 commits intoRTGS2017:mainfrom
69gg:fix/config-encoding
Feb 19, 2026
Merged

fix: config_manager 读取 config.json 时自动检测编码#226
69gg merged 2 commits intoRTGS2017:mainfrom
69gg:fix/config-encoding

Conversation

@69gg
Copy link
Collaborator

@69gg 69gg commented Feb 18, 2026

问题

_load_config_file 硬编码 encoding='utf-8',当 config.json 为 UTF-16 LE BOM 编码时(旧版安装或打包版),读取抛 UnicodeDecodeError,被 except 吞掉返回 None,导致 update_config 静默返回 False

表现:前端填写的 API key 传到后端后不生效(LLM 仍使用占位符 sk-placeholder-key-not-set),且配置变更重启后失效。

修复

改用 detect_file_encodingcharset_normalizer 自动检测),与 system/config.pyload_config 保持一致。

变更

system/config_manager.py_load_config_file 改用 detect_file_encoding 替代硬编码 utf-8

_load_config_file 硬编码 utf-8 导致 UTF-16 LE BOM 文件读取失败,
update_config 静默返回 False,API key 及所有配置变更无法持久化。
改用 detect_file_encoding(与 load_config 保持一致)。

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@69gg 69gg marked this pull request as draft February 18, 2026 15:32
PyInstaller 打包后 __file__ 指向 sys._MEIPASS(只读),
导致 _save_config_file 写入失败,配置永远无法持久化。

- 新增 IS_PACKAGED / get_config_path():打包时用 sys.executable 同级目录
- bootstrap_config_from_example:打包时从 sys._MEIPASS 读取模板
- config_manager 所有路径改用 get_config_path()

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@69gg 69gg marked this pull request as ready for review February 18, 2026 15:48
@69gg 69gg merged commit e18bb0d into RTGS2017:main Feb 19, 2026
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

Comments