Repository navigation
重构:清理针对不可能状态的防御性代码 - #26
Merged
Merged
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.
改了什么
基于 main
662a771(v1.6.2)删除 8 处针对不可能发生状态的防御:serverinfo.pymost = max(votes.values())后if most <= 0: return Noneif not votes: return None,计数只由+1增加scanner.py_loads_lenient里len(raw) > METADATA_SIZE_LIMIT_read_entry_capped超限即抛,同一道边界查两遍downloads.pyresolve_folder的「Defence in depth」再resolve()比较父目录resolve()系统调用downloads.pyoutcome = None+outcome is not None+# type: ignoreinstaller.pyrecord["file"]后再判空 + 再is_safe_component_install_one_locked校验过__init__.pytry: getattr(target, name) except AttributeError: continue_NUMERIC_RANGES是静态表且测试反过来断言每条路径都存在__init__.pyif server is not None: server.logger.debug(...)server.logger,此处必不为 None__init__.pytry: DownloadLedger(...) except Exception: return 0read_json(已吞 OSError/ValueError),无失败路径为什么
按既定口径:不为「保证 0 报错」写过多防御性代码,只保留真实可达失败状态的防护。
保留的防护
Modrinth HTTP 重试与限流、缓存/台账损坏恢复、版本比较边界、单个坏 jar 隔离、删除前 TOCTOU 复查、并发锁与 finally 复位——未动。
验证
pytest -m "not e2e":883 passed, 2 deselected(改前基线同样全绿)ruff check .(与 CI 同版本 0.17.0):All checks passedtools/check_python_floor.py:53 个文件通过 3.8 检查tools/mutation_check.py的 12 个锚点逐条套用到当前源码,12/12 仍唯一命中