fix: config_manager 读取 config.json 时自动检测编码#226
Merged
69gg merged 2 commits intoRTGS2017:mainfrom Feb 19, 2026
Merged
Conversation
_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>
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>
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.
问题
_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_encoding(charset_normalizer自动检测),与system/config.py的load_config保持一致。变更
system/config_manager.py:_load_config_file改用detect_file_encoding替代硬编码utf-8。