Repository navigation
Conversation
info() reads a save folder's chives.json and calls meta.get('save_directory')
with no type guard. A well-formed JSON that is not an object (list/null/
number/string) raised AttributeError, exit 1, while main() only catches
(ValueError, struct.error, OSError). pack_from_dir in the same file already
guards its index with ValueError(f'{path}: {field} must be ...'), which main
turns into one ERROR line exit 2. Raise the same ValueError when chives.json
is not an object. Five synthetic subtests plus a positive control, red before
green after.
|
Tested 2e4e238 on Windows 11, CPython 3.14.7, CPU only (no GPU, no game files): pass.
I also ran AI-assisted. |
|
Tested 2e4e238 merged with main 3faac55 on Linux (WSL2, Ubuntu), CPython 3.12.16,
Negative control: with |
|
Tested
|
|
Gap (checked on Linux, Python 3.14.8, synthetic ASAV from the tests'
One option: a small shared reader used by both callers that checks |
…checks
The two PRs report the same mistake, so they should use the same words for it. This one only adds
the kind that was found ("not an array"). With this change ItsNotRexed#4968's InfoChivesTest passes on this
branch as it stands. Whichever of the two lands second rebases only the code in info(), not a test.
AI-assisted.
|
@SebSilent a heads-up: #5240 covers the same non-object At AI-assisted. |
Claimed in the coordination issue as: new BUILD item, saves info non-object chives.json
What and why
tools/saves.py info <folder>reads the folder'schives.jsonand prints the save directory:There is no guard on the parsed value's type. A well-formed JSON whose top level is not an object (
[],null,5,"x") reachesmeta.get(...)and raisesAttributeError('list' object has no attribute 'get', etc.).main()only catches(ValueError, struct.error, OSError):so the
AttributeErrorescapes as a full traceback, exit 1. Invalid JSON syntax already exits 2 (it is aValueError); only the well-formed-non-object case crashes.pack_from_dirin the same file already guards its parsed index the intended way:This makes
info()consistent: raiseValueError(f'{cj}: chives.json must be an object')when the parsed meta is not a dict, whichmain()turns into oneERROR:line, exit 2.Tested
Linux (CachyOS), Python 3.14.10. CPU only, no game files; every
chives.jsonfixture is synthetic JSON written by the test.python -I tests/test_saves.py: 63 tests OK (1 skip), including the newInfoChivesTest:test_a_non_object_chives_is_one_error_line: 5 subtests ([],null,5,"x",[1, 2]), each asserting exit 2, noTraceback, andERROR: ... chives.json must be an objecton stderr.test_an_object_chives_still_reports_the_folder: a valid{"save_directory": "SLOT0"}still printssave folder, dir SLOT0, exit 0.AttributeErrortraceback); green after with the fix.python -m compileall -q tools/saves.py tests/test_saves.py,git diff --check: clean.Note: open #1438 edits
extract/packand adds helpers afterinfo(), not thechives.jsonread; #4872'smeta.getis inimport_saves(chives.dat). Whichever lands second rebases.AI-assisted: yes (Tacit).
Checklist
docs/design.md, with how it was confirmed. (n/a, no translator rule)