Repository navigation
Report errors of jsondiff and jsonpatch in one line - #271
Open
stefankoegl wants to merge 1 commit into
Open
stefankoegl wants to merge 1 commit into
stefankoegl wants to merge 1 commit into
Conversation
A patch that could not be applied, an invalid patch, invalid JSON and errors reading or writing files ended the programs with a traceback. They now print 'PROGRAM: error: MESSAGE' to stderr and exit with status 2, as they already do for wrong arguments and files that can't be opened. Messages for invalid JSON and invalid UTF-8 name the file. Status 2 keeps errors apart from status 1, with which jsondiff reports that the files differ. Other exceptions, which would be bugs, still show a traceback. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PewzpjVeke4LTQ7Q88nyu6
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A patch that could not be applied, an invalid patch, invalid JSON, and errors reading or writing files all ended the command line programs with a Python traceback. They now print one line to stderr and exit with status 2:
This is the format and status argparse already uses for wrong arguments and files that cannot be opened.
Behaviour changes
jsondiffreports that the files differ (asdiffdoes). Scripts that test for "non-zero" are unaffected; scripts that testjsonpatchfor exactly 1 would need changing.<stdin>.JsonPatchException,JsonPointerException,ValueError(JSON and encoding errors) andOSError. Anything else would be a bug and still shows a traceback. Ctrl-C still exits silently with status 1.Internally,
diff_files()andpatch_files()now raise aValueErrorthat wraps theJSONDecodeError(as__cause__) in order to carry the file name.Docs and tests
doc/commandline.rstdescribes the exit statuses.python tests.pypasses with coverage at 100%; flake8 andsphinx-build -Ware clean (Python 3.13).Touches
jsonpatch_cli.pyandtests.pyin different places than #270, so the two should merge in either order.🤖 Generated with Claude Code
https://claude.ai/code/session_01PewzpjVeke4LTQ7Q88nyu6