fix(tools): report deeply nested patch advisor JSON and TOML as errors #12787
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12787"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-29T09:05:15Z.
What
suggest_patches.pyreads the title'sparam.json, the catalog'sindex.jsonand each entry's patch file withjson.loadsandtomllib.loadsand reports an unreadable file asPatch advisor: ...with exit code 2, or rejects only the entry whose patch file is unreadable, but only forOSError,ValueError,json.JSONDecodeErrorandtomllib.TOMLDecodeError. A file nested deeper than the interpreter's recursion limit raisesRecursionError, which is none of these, so the tool printed a traceback and exited with 1. This catchesRecursionErrorin the top-level handler, soparam.jsonandindex.jsonget the usual message and exit code 2, and in the per-entry handler, so one catalog entry whose patch file is nested too deeply for the TOML decoder is rejected on its own and the remaining entries are still checked, like any other unreadable patch file. The new tests pick their nesting depth fromsys.getrecursionlimit()and check that the decoder really fails on it, so they do not depend on the standard library's message text.Tested
668f600596) all 37 tests oftools/tests/test_suggest_patches.pypass (2 skipped, as before). At the first commit (4e6047eccf) the nested-JSON test failed with thesuggest_patches.pyofmain14b3441f3d, differing only in theexceptclause; the new patch-file test fails when the per-entryexceptlacksRecursionError.suggest_patches.pythe patch-file test fails.main(5454cd2e45, which now has the offline catalog validator) merges without conflict, andtools/tests/test_suggest_patches.pytogether withtools/tests/test_validate_patch_catalog.pypasses (52 tests, 3 skipped).check_conventions --base upstream/mainpasses.Overlap
Two open PRs change
tools/suggest_patches.py: #12340 (symbolic link loops, also its test) and #12769 (JSON output). I took the changed files of each of the 1418 open PRs fromgit diff --name-onlyagainst its merge base, and re-checked these two against this head andmain5454cd2e45.git merge-treeof this branch with #12340 reports one content conflict intools/suggest_patches.py, next to theexceptclause this change edits, while #12340 is clean on its own againstmain; whichever lands second needs a one-line keep-both resolution. #12769 merges cleanly with this branch. Neither is a prerequisite, so there is noDepends on. #12263, which I had listed in the first version, has been merged; itsvalidate_patch_catalog.pyreports deeply nestedindex.jsondata on its own and added noRecursionErrorhandling tosuggest_patches.py.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-29T10:28:56Z.
Review: COMMENTED
I checked head
4e6047eccfon macOS arm64, where the body says it was not run.What I confirmed
tools/tests/test_suggest_patches.pypasses 36/36 on Python 3.12.13, 3.13.13, 3.14.8 and 3.15.1. The new test fails on themainsuggest_patches.pywith the expectedRecursionError(2 errors, 3.13 and 3.15). The system Python 3.9.6 can't import the module because there is notomllib, and that is the same onmain.check_conventions --base upstream/main,git diff --checkandgit merge-treeagainstmainare all clean.1. A deeply nested
patch.tomlstill escapes the per-entry handling (non-blocking, maybe a follow-up)tomllibraisesRecursionErrortoo. On all four interpreters,a = [[[…]]]fails at every depth I tried from 1,000 up. That happens invalidate_entry(L158), and the per-entryexcept (OSError, ValueError, tomllib.TOMLDecodeError)at L213 doesn't catch it. My test catalog had two entries: entry 1 points at a broken patch file and entry 2 is the valid fixture entry.not toml [[[)rejected: Expected '='…, entry 2 Recommended, rc 0Patch advisor: maximum recursion depth exceeded, rc 2, entry 2 never checkedSo the PR turns the traceback into a clean error, which is better. But one over-nested patch file now fails the whole run, while any other unreadable patch file only rejects its own entry. You could add
RecursionErrorto the L213 tuple too, either here or in a follow-up. The title only mentions JSON, so I'm leaving that call to you.2. Overlap paragraph
#12769 (StoneDC, opened 08:40Z, before this PR) rewrites the same top-level
exceptblock (print→emit).git merge-tree --write-tree pr-12769 pr-12787reportsCONFLICT (content): Merge conflict in tools/suggest_patches.py, and the bot's overlap comment lists it as well. The body says each open PR merges cleanly with this branch, so it may have used an older PR list. The conflict is a one-line keep-both, but it should be listed.Nit
If an assertion inside the
subTestloop fails,target.write_text(original, …)is skipped. The next subtest then runs with the nested file still in place.self.addCleanupor atry/finallywould keep a failure from spreading to the second target.AI-assisted: yes