1
0
mirror of https://github.com/stedolan/jq.git synced 2024-05-11 05:55:39 +00:00

Fix halt_error to print message without prefix in raw mode (fix #1902) (#2632)

This commit is contained in:
itchyny
2023-06-27 07:33:21 +09:00
committed by GitHub
parent e468eaa396
commit 98835eec24
2 changed files with 14 additions and 4 deletions

View File

@ -216,12 +216,14 @@ static int process(jq_state *jq, jv value, int flags, int dumpopts) {
jv_free(exit_code);
jv error_message = jq_get_error_message(jq);
if (jv_get_kind(error_message) == JV_KIND_STRING) {
fprintf(stderr, "jq: error: %s", jv_string_value(error_message));
// No prefix should be added to the output of `halt_error`.
fwrite(jv_string_value(error_message), 1,
jv_string_length_bytes(jv_copy(error_message)), stderr);
} else if (jv_get_kind(error_message) == JV_KIND_NULL) {
// Halt with no output
} else if (jv_is_valid(error_message)) {
error_message = jv_dump_string(jv_copy(error_message), 0);
fprintf(stderr, "jq: error: %s\n", jv_string_value(error_message));
fprintf(stderr, "%s\n", jv_string_value(error_message));
} // else no message on stderr; use --debug-trace to see a message
fflush(stderr);
jv_free(error_message);

View File

@ -275,11 +275,19 @@ if [ -n "$($VALGRIND $Q $JQ -n 'halt_error(1)' 2>&1)" ]; then
echo "jq halt_error(1) had unexpected output" 1>&2
exit 1
fi
if [ -n "$($VALGRIND $Q $JQ -n '"xyz\n"|halt_error(1)' 2>/dev/null)" ]; then
if [ -n "$($VALGRIND $Q $JQ -n '"xyz\n" | halt_error(1)' 2>/dev/null)" ]; then
echo "jq halt_error(1) had unexpected output on stdout" 1>&2
exit 1
fi
if [ "$($VALGRIND $Q $JQ -n '"xyz\n"|halt_error(1)' 2>&1)" != "jq: error: xyz" ]; then
if [ "$($VALGRIND $Q $JQ -n '"xy" | halt_error(1)' 2>&1 || echo "z")" != "xyz" ]; then
echo "jq halt_error(1) had unexpected output" 1>&2
exit 1
fi
if [ "$($VALGRIND $Q $JQ -n '"x\u0000y\u0000z" | halt_error(1)' 2>&1 | tr '\0' '.')" != "x.y.z" ]; then
echo "jq halt_error(1) had unexpected output" 1>&2
exit 1
fi
if [ "$($VALGRIND $Q $JQ -n '{"a":"xyz"} | halt_error(1)' 2>&1)" != '{"a":"xyz"}' ]; then
echo "jq halt_error(1) had unexpected output" 1>&2
exit 1
fi