Repository navigation
Continue CLI batches after malformed JSON input - #92
xingzhao-ji wants to merge 1 commit into
Conversation
|
Thanks for your contribution! Somehow I have the feeling that this behavior should be optional. What do you think about a |
Wkhanex
left a comment
There was a problem hiding this comment.
The mixed-batch fix works for malformed JSON: I ran the real PR CLI with an invalid file at the beginning, middle and end of two valid files; all three runs retained both valid outputs and exited 1 without a traceback. A remaining adjacent malformed-input case still aborts the batch: a file containing bytes b'{"a":"\xff"}' raises UnicodeDecodeError, and the following valid file is never processed. Consider handling UnicodeDecodeError alongside JSONDecodeError, with the same file-labelled diagnostic and continuation behavior. AI-assisted review on Python 3.12; real CLI subprocesses used only synthetic temporary files.
The CLI documents that remaining files are processed when a pointer cannot be resolved in one input. A malformed JSON file currently escapes that per-file handling:
json.load()raisesJSONDecodeError, the process prints a traceback, and valid files later in the batch are never processed.For example, with
invalid.jsoncontaining{"a": }andvalid.jsoncontaining{"a": 1},jsonpointer /a invalid.json valid.jsoncurrently prints no result. With this change, it reports the parse failure to stderr, prints1for the valid file, and exits with status 1.This patch catches
JSONDecodeErroronly around loading each document, reports the input filename and decoder error location, and continues with the remaining files. It retains status 1 for the batch and documents this case. Usage errors such as missing files retain their existing behavior.Regression tests cover empty input, invalid syntax, extra top-level data, malformed input at every position in a three-file batch, and a batch containing both malformed JSON and an unresolved pointer.
Validation:
AI disclosure: This contribution was prepared by an OpenAI coding assistant. The reproductions and checks above were executed in its development environment.