-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
jq -e always returns 0 for empty input #1142
Comments
Exactly, @rfletcher! With the current behavior of I ended up with a workaround like this in my script:
There appears to be no way to handle or work around this with just a single jq filter/invocation — but there should be! (Even if we had to add another flag, like By the way, this issue came up again in #1497. |
For anyone who (like me) comes across this trying to check whether a file is valid json, you can use one of these workarounds until the underlying jq issue is fixed: To just check that filename.json is valid json: To also check for the presence of a |
* Set default error code to -4 in main(), Fixes jqlang#1142 * fix --exit-code with more than one object in input, Fixes jqlang#1139 - Return code 1 or 4 based on last output, not last input.
* Set default error code to -4 in main(), Fixes jqlang#1142 * fix --exit-code with more than one object in input, Fixes jqlang#1139 - Return code 1 or 4 based on last output, not last input.
another workaround: $ echo | jq -es 'if . == [] then null else .[] | your-pipe end'
$ echo $?
1 |
This reverts commit b233ace while preserving bd3f96a. jq, even with -e, does not exit non-zero when given an empty input. This is apparently a known feature: jqlang/jq#1497 jqlang/jq#1142 Thus, revert this oversimplification which leads to problems when curl fails, or otherwise returns an empty response body. Closes #29.
* Set default error code to -4 in main(), Fixes jqlang#1142 * fix --exit-code with more than one object in input, Fixes jqlang#1139 - Return code 1 or 4 based on last output, not last input.
This is still an issue with jq version 1.6
|
jq -e
always exits with status 0 when passed empty input. For example:Consider a use case like this one:
If the API call fails and output is only written to stderr,
take-action
will still run as though the call succeeded, and "some-value" had been set.This may be related to issue #667, but that one has been fixed on master, and this bug is still present.
The text was updated successfully, but these errors were encountered: