Skip to content

Commit

Permalink
Fix exit code on JSON parse error (jqlang#2654)
Browse files Browse the repository at this point in the history
  • Loading branch information
itchyny authored Jul 6, 2023
1 parent 95625c3 commit a881532
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -698,12 +698,12 @@ int main(int argc, char* argv[]) {
// Parse error
jv msg = jv_invalid_get_msg(value);
if (!(options & SEQ)) {
// --seq -> errors are not fatal
ret = JQ_OK_NO_OUTPUT;
ret = JQ_ERROR_UNKNOWN;
fprintf(stderr, "jq: parse error: %s\n", jv_string_value(msg));
jv_free(msg);
break;
}
// --seq -> errors are not fatal
fprintf(stderr, "jq: ignoring parse error: %s\n", jv_string_value(msg));
jv_free(msg);
}
Expand Down
11 changes: 10 additions & 1 deletion tests/shtest
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ if $VALGRIND $Q $JQ -e . $d/input; then
exit 2
fi

# Regression test for #2146
if echo "foobar" | $JQ .; then
printf 'Issue #2146 is back?\n' 1>&2
exit 1
elif [ $? -ne 5 ]; then
echo "Invalid input had wrong error code" 1>&2
exit 1
fi

# Regression test for #1534
echo "[1,2,3,4]" > $d/expected
printf "[1,2][3,4]" | $JQ -cs add > $d/out 2>&1
Expand Down Expand Up @@ -204,7 +213,7 @@ else
fi

## Regression test for issue #2378 assert when stream parse broken object pair
echo '{"a":1,"b",' | $JQ --stream > /dev/null 2> $d/err
echo '{"a":1,"b",' | $JQ --stream > /dev/null 2> $d/err || true
grep 'Objects must consist of key:value pairs' $d/err > /dev/null

## Regression test for issue #2572 assert when using --jsonargs and invalid JSON
Expand Down

0 comments on commit a881532

Please sign in to comment.