Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exit code is 0 even if there is a mismatch. #5

Open
vi opened this issue Aug 20, 2021 · 3 comments
Open

Exit code is 0 even if there is a mismatch. #5

vi opened this issue Aug 20, 2021 · 3 comments

Comments

@vi
Copy link

vi commented Aug 20, 2021

$ json_diff d '{} ' ' {}' ; echo $?

No mismatch was found.
0
$ json_diff d '[] ' ' {}' ; echo $?
Mismatch at root.
0
@ksceriath
Copy link
Owner

Mismatch in the input json does not necessarily mean a failure for the tool itself.

Frankly, I am not convinced that the tool needs to return a non-zero exit code if the inputs don't match. Can you help me with your use case?

@vi
Copy link
Author

vi commented Aug 21, 2021

Typically comparison tools (e.g. diff, cmp) return non-zero exit code to mean "mismatch" and zero code to mean "no differences".

Failure for the tool itself is typically signaled by the non-zero non-one exit code, e.g. "2".

Exit code distinction is typically needed for comparting JSONs noninteractively. json_diff's comparison ignores whitespace and order of keys, which is tricky to attain in Bash without using additional tools.

@ksceriath
Copy link
Owner

Okay, yeah that makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants