Repository navigation
root_spill_census: report an unreadable index as one error line, not a traceback - #7429
bobcatchris wants to merge 1 commit into
Conversation
…a traceback `main`'s `__main__` guard wraps only the stdout reconfigure, so a missing --index/--carve, bytes that are not UTF-8, an empty file, text that is not JSON or a file nested deeper than the parser can hold all end in a traceback (FileNotFoundError, UnicodeDecodeError, JSONDecodeError, RecursionError) instead of a diagnostic and exit 2. Both indexes now go through one reader that keeps the existing UTF-8 BOM handling and turns each failure into `error: cannot read <path>: <reason>` or `<path> is not valid JSON: <detail>`, returning 2. The census, the --json overwrite guard and every verdict are unchanged; a successful read still yields exactly the same summary. Tests: four read failures for --index, one for --carve, and a deeply nested index, each asserting no traceback and no report written; the nine existing CLI tests and six census tests still pass (21 total).
6331184 to
5d93ea3
Compare
Independent Review of PR #7429Verdict: LGTM / Approve. Environment
Negative Control Reproduction on
|
|
Independent Windows/Python 3.10 validation on
The shared |
|
Tested 5d93ea3 on Windows 11 (CPU only, no GPU needed): pass Windows 11 Pro, Python 3.14.7, CPU only (no GPU or game files involved); pytest/numpy/Pillow pinned from
AI-assisted (Claude Code, Claude Opus 5.5). |
|
Closing as a duplicate: #6105 (open, earlier) and #5712 cover this item, and main's #6701 ( What this PR had that #6105 does not, for its author to take if useful:
No code from this branch is needed beyond that. AI-assisted. |
|
Three PRs cover this topic. Facts at current
I'm not closing this while it is the only mergeable, complete fix; the maintainer should pick the base. If #5712 is preferred, the unique pieces here are AI-assisted. |
Summary
tools/root_spill_census.pyprinted a traceback for every input it could not read. The__main__block guards only the stdout reconfigure, somain()'sjson.loadcalls were unguarded:All three were measured on
main1924c8f91with synthetic files only. A deeply nested file did the same throughRecursionError.Change
read_json(path)helper reads both--indexand--carve. It keeps the existingutf-8-sighandling (a BOM-saved index is still JSON, tested today) and turnsOSError,UnicodeDecodeError,json.JSONDecodeErrorandRecursionErrorinto one line:error: cannot read <path>: <reason>or<path> is not valid JSON: <detail>.main()prints that line to stderr and returns2.--baseoverrides,--expect-no-spill's exit 1, the "not a translator index" usage error and the--jsonoverwrite/folder guards are untouched, and a readable index still produces byte-identical output.Tests
tests/test_root_spill_census.py, 21 tests, all passing withpython -I tests/test_root_spill_census.py:--indexcases (missing, not UTF-8, empty, not JSON), one unreadable--carve, and an index nested 100,000 levels deep. Each asserts exit 2, theerror:line naming the path, noTraceback, and that no report was written.--basedefault, the write-failure line and the input-overwrite refusals, unchanged and still green.The same three commands against
main's copy of the tool exit 1 with the tracebacks above, which is the negative control for the new tests.No game files, no GPU: the tests build their indexes in a temporary folder.
AI-assisted.