Repository navigation
fix(tools): report deeply nested compile commands JSON as a usage error - #13884
Conversation
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
The one-line exception fixes the malformed-JSON traceback, and the regression test detects the bug on the base revision.
What I ran
Reviewed head 820e43ad7e68d35b048eefdf736825b1e4b61292. The focused checks used base 8f55414024c614b32548254e59e80bd3f0085231; a fresh merge preview against current GitHub main 4e2c5a72e6ad77abb8d001083439a0e9da9841f0 was clean. Environment: Linux x86_64, Python 3.11.2.
python3 -m py_compile tools/check_compile.py
python3 -m unittest tools.tests.test_check_compile
python3 tools/check_test_registration.py --scripts
git diff --check 8f55414024c614b32548254e59e80bd3f0085231...820e43ad7e68d35b048eefdf736825b1e4b61292
python3 tools/check_conventions.py --base 8f55414024c614b32548254e59e80bd3f0085231 --head 820e43ad7e68d35b048eefdf736825b1e4b61292 --title 'fix(tools): report deeply nested compile commands JSON as a usage error' --body /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13884-820e43ad7e68/pr-body.mdResults
| Check | Result |
|---|---|
| Python syntax | Passed |
tools.tests.test_check_compile |
Passed: 62 tests, 9 skipped |
| Script test registration | Passed: 230 test scripts registered |
| Diff and conventions | Passed |
| Merge preview | Clean against current main 4e2c5a72e6ad77abb8d001083439a0e9da9841f0 |
| Hosted checks | Conventions and intake passed; labels and eligibility were queued at the final status check |
Unedited unit-test output
............s...s..................s.......s..s...s..s...ss...
----------------------------------------------------------------------
Ran 62 tests in 9.652s
OK (skipped=9)
Negative control
| Assertion | Change to code under test | Outcome |
|---|---|---|
| Deeply nested JSON exits with usage status 2 and no traceback | Ran the new test against the base version without the RecursionError handler |
Failed as expected: the base exits 1 with a RecursionError traceback |
Unedited negative-control output
F...........s...s..................s.......s..s...s..s...ss...
======================================================================
FAIL: test_excessively_nested_compilation_databases_are_rejected_without_a_traceback (tools.tests.test_check_compile.CheckCompileDatabaseTests.test_excessively_nested_compilation_databases_are_rejected_without_a_traceback)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13884-820e43ad7e68/negative-control-base-57441e7e/tools/tests/test_check_compile.py", line 510, in test_excessively_nested_compilation_databases_are_rejected_without_a_traceback
self.assertEqual(result.returncode, 2, result.stdout + result.stderr)
AssertionError: 1 != 2 : Traceback (most recent call last):
File "/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13884-820e43ad7e68/negative-control-base-57441e7e/tools/check_compile.py", line 432, in <module>
sys.exit(main())
^^^^^^
File "/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13884-820e43ad7e68/negative-control-base-57441e7e/tools/check_compile.py", line 418, in main
checked, failed = check(root, args.build, files, args.jobs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13884-820e43ad7e68/negative-control-base-57441e7e/tools/check_compile.py", line 368, in check
commands = index(build, root)
^^^^^^^^^^^^^^^^^^
File "/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13884-820e43ad7e68/negative-control-base-57441e7e/tools/check_compile.py", line 130, in index
for entry in entries(build):
^^^^^^^^^^^^^^
File "/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13884-820e43ad7e68/negative-control-base-57441e7e/tools/check_compile.py", line 106, in entries
return compilation_database(manifest.read_text(encoding="utf-8-sig"), manifest)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13884-820e43ad7e68/negative-control-base-57441e7e/tools/check_compile.py", line 73, in compilation_database
database = json.loads(text)
^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/json/decoder.py", line 353, in raw_decode
obj, end = self.scan_once(s, idx)
^^^^^^^^^^^^^^^^^^^^^^
RecursionError: maximum recursion depth exceeded while decoding a JSON array from a unicode string
----------------------------------------------------------------------
Ran 62 tests in 10.328s
FAILED (failures=1, skipped=9)
Sources
- The reviewed
check_compile.pychange handlesRecursionErroralongside malformed-input errors. - The new regression test at the reviewed head checks the usage exit status and absence of a traceback.
Not verified
The author reports Windows and WSL runs, which I did not independently reproduce. The GitHub eligibility and label checks had not completed at review time. No full AnyPS5 build was needed or run for this Python-only change.
|
@xXPBSXx Reviewed at The current catch covers repository discovery, changed-file discovery and all of |
…N is decoded Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
MarcZX10
left a comment
There was a problem hiding this comment.
Re-checked — new head, looks good
The narrower parser handler fixes the earlier concern, and the added regression confirms unrelated recursion errors still propagate.
What I ran
Reviewed head 48f7b2e9334d2f4e48bc1d32a048256dc23c0c8c against base 8f55414024c614b32548254e59e80bd3f0085231; the merge preview is clean and both SHAs remained unchanged through the precheck. Environment: Linux x86_64, Python 3.11.2.
python3 -m py_compile tools/check_compile.py
python3 -m unittest tools.tests.test_check_compile
python3 tools/check_test_registration.py --scripts
python3 tools/check_conventions.py --base 8f55414024c614b32548254e59e80bd3f0085231 --head 48f7b2e9334d2f4e48bc1d32a048256dc23c0c8c --title 'fix(tools): report deeply nested compile commands JSON as a usage error' --body /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13884-48f7b2e9334d/pr-body.mdResults
| Check | Result |
|---|---|
| Python syntax | Passed |
tools.tests.test_check_compile |
Passed: 63 tests, 9 skipped |
| Script test registration | Passed: 230 scripts registered |
| Diff and conventions | Passed |
| Negative control on base | Passed as a control: the new deep-JSON regression fails on base with the original RecursionError traceback |
| Test-quality helper | Unavailable in the isolated checkout; this did not affect the test run |
| Hosted CI | Ubuntu relinker, ASan relinker, eligibility, conventions, and labels passed; Windows/Linux product jobs were skipped; Windows relinker and two macOS relinker jobs were pending at the latest status check |
Unedited focused test output
.............s...s..................s.......s..s...s..s...ss...
----------------------------------------------------------------------
Ran 63 tests in 10.109s
OK (skipped=9)
Findings
Blocking
None found.
Non-blocking
The test-quality helper could not run because tools/pr_test_quality.py was absent from the isolated checkout. Windows/Linux product jobs were skipped; they are not needed to validate this Python-only change.
Sources
|
Thanks, you are right: the On Windows (Python 3.12.10) and on WSL (Python 3.12.3), both tests passed 3 of 3 runs on 44ed68cca1, the deep-database test failed 3 of 3 runs with AI-assisted (Claude Code). |
|
Checked the narrowed |
What
tools/check_compile.pyreadscompile_commands.json(or the output ofninja -t compdb) withjson.loadsincompilation_database, andmainturnsjson.JSONDecodeError,OSErrorandValueErrorinto a usage error. ARecursionErroris none of these, so a deeply nested file ends in a traceback and exit code 1 instead of the usage error with exit code 2 that the other malformed databases get. This catchesRecursionErroronly aroundjson.loadsincompilation_databaseand raises the existingValueErrorfrom it, so aRecursionErrorfrom anywhere else still propagates. A few lines incheck_compile.py, plus two tests.Tested
Python 3.12.10 on Windows and Python 3.12.3 on WSL (Ubuntu 24.04).
test_excessively_nested_compilation_databases_are_rejected_without_a_tracebackprobes a nesting depth fromsys.getrecursionlimit()upward untiljson.loadsitself raisesRecursionError(and fails if it never does), then checks exit code 2, noTracebackin stderr, and that the "expected an array of command objects" message is not the one shown.test_a_recursion_error_outside_the_database_parser_is_not_a_usage_errormakescheck()raiseRecursionErrorand expects it to propagate out ofmain. On both systems each test passed 3 of 3 runs on 44ed68cca1; the first failed 3 of 3 runs withtools/check_compile.pyequal tomain, the second failed 3 of 3 runs with theexceptinmainwidened toRecursionError. After reformatting one line of the second test (48f7b2e), both tests passed once more on both systems and the second test failed once more against the widenedexcept. All 9 tests ofCheckCompileDatabaseTestspassed on 44ed68cca1.tools/check_conventions.py --base upstream/mainpasses. Based onmaine8c25dd3ba, and it merges withmain73f4f7e06ewithout a conflict (checked 2026-10-31 13:30 UTC). Not run: Python 3.13 or newer.Overlap
I took the changed files of each of the 1611 open pull requests from
git diff --name-onlyagainst its merge base (started 2026-10-31 at 08:20 UTC). Three change the touched files: #12874 and #9547 changetools/check_compile.py, #13239 changestools/tests/test_check_compile.py. Checked on 2026-10-31 at 09:56 UTC withgit merge-treeagainstmainc3c45d7: this head alone merges cleanly, and so do its pairs with each of the three. Checked once more on 2026-10-31 at 11:00 UTC againstmain602c0e417c: none of the 82 pull requests opened since 06:30 UTC changes these two files, and the pairs with #12874, #9547 (my own) and #13239 still merge cleanly.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).
🤖 Generated with Claude Code