fix: 配置文件加载失败的时候输出详情 #8204#8230
Open
IITII wants to merge 1 commit into
Open
Conversation
* 某些情况下重启 AstrBot 后, 文件 /AstrBot/data/cmd_config.json 可能为空
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- When checking for an empty config file, consider using
if not conf_str.strip():so files with only whitespace/newlines are also treated as empty rather than causing a JSON parse error. - Instead of
raise eafter logging, use a bareraiseto preserve the original traceback and make debugging easier.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- When checking for an empty config file, consider using `if not conf_str.strip():` so files with only whitespace/newlines are also treated as empty rather than causing a JSON parse error.
- Instead of `raise e` after logging, use a bare `raise` to preserve the original traceback and make debugging easier.
## Individual Comments
### Comment 1
<location path="astrbot/core/config/astrbot_config.py" line_range="69-71" />
<code_context>
+ raise EnvironmentError(f'文件 {config_path} 为空, 请手动处理...')
+ try:
+ conf = json.loads(conf_str)
+ except Exception as e:
+ logger.error(f'读取文件失败 {config_path}: {e}')
+ raise e
dashboard_conf = conf.get("dashboard")
legacy_dashboard_password_change_required = bool(
</code_context>
<issue_to_address>
**issue:** Re-raising the caught exception with `raise e` drops the original traceback context.
`raise e` overwrites the original traceback and loses the full stack context. Use a bare `raise` to preserve the original traceback while keeping the logging as-is:
```python
except Exception as e:
logger.error(f'读取文件失败 {config_path}: {e}')
raise
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces error handling for empty or malformed configuration files in astrbot_config.py. The feedback suggests using more appropriate exception types like ValueError instead of EnvironmentError, catching specific json.JSONDecodeError exceptions, and using a bare raise to preserve stack traces. Additionally, it is recommended to consider automatic recovery with default configurations and to include unit tests for these new logic paths.
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.
[Bug]在更新到4.25.0后,遇到了desktop无法登录的问题 #8204
可以打开web ui 但无法配置模型,其他功能键也无法使用,之前配置的插件也全部消失了 #8231
TODO: 不清楚空配置文件的情况下, 应该载入默认配置还是直接抛异常, 目前是直接抛异常.
如果, 修复对应配置文件之后还是无法登陆, 可能是 webui 版本不一致导致的. 手动下载替换 ./data/dist 文件夹
https://github.com/AstrBotDevs/AstrBot/releases/
https://docs.astrbot.app/use/webui.html#%E6%9B%B4%E6%96%B0%E7%AE%A1%E7%90%86%E9%9D%A2%E6%9D%BF
(所以是究竟哪里自动更新了, 导致旧版本重启之后问题不断吗,,,
Modifications / 改动点
Screenshots or Test Results / 运行截图或测试结果
系统配置/白名单/模型配置都被被清空了. 已安装的插件还在.Checklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。