优化:inno路由文件读取对损坏行增加容错处理#142
Open
Kailigithub wants to merge 1 commit into
Open
Conversation
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.
优化说明
/api/inno/get_tm/{user_id}和/api/inno/get_pr/{user_id}在读取static/tm/t{userid}.txt、static/tm/f{userid}.txt时使用裸的[ast.literal_eval(x) for x in lines]。如果文件中有任何一行因写入中断、并发覆盖或编码错误导致ast.literal_eval抛ValueError/SyntaxError,整个接口会返回 500,用户的时间管理数据就完全无法访问。add_study_time已经使用相同的容错模式(line 121)。本次改动把另外三处裸调用统一收敛到新增的_safe_literal_eval_lines辅助函数:解析失败的行通过logger.warning记录后跳过,合法行正常返回。行为差异
[](之前会 500)验证
py_compile通过。/tmp/test_inno_safe_parse.py覆盖五种情况:ast.literal_eval行为等价并通过 git-stash 三步验证:原代码在损坏行上抛
SyntaxError,新代码正常返回。