Skip to content
Myr

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

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by itchyny · committed by GitHub · parent e468eaa · Browse files · 2 files+14 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+14 added−4 removed

  • tests:+10 added−2 removed
  • other:+4 added−2 removed

2 files+14 added−4 removed

modified:src/main.c+4 added-2 removed
214 unmodified lines
215 ret = JQ_ERROR_UNKNOWN;216 jv_free(exit_code);217 jv error_message = jq_get_error_message(jq);218 if (jv_get_kind(error_message) == JV_KIND_STRING) {219 fprintf(stderr, "jq: error: %s", jv_string_value(error_message));219 // No prefix should be added to the output of `halt_error`.220 fwrite(jv_string_value(error_message), 1,221 jv_string_length_bytes(jv_copy(error_message)), stderr);222 } else if (jv_get_kind(error_message) == JV_KIND_NULL) {223 // Halt with no output224 } else if (jv_is_valid(error_message)) {225 error_message = jv_dump_string(jv_copy(error_message), 0);224 fprintf(stderr, "jq: error: %s\n", jv_string_value(error_message));226 fprintf(stderr, "%s\n", jv_string_value(error_message));227 } // else no message on stderr; use --debug-trace to see a message228 fflush(stderr);229 jv_free(error_message);230 } else if (jv_invalid_has_msg(jv_copy(result))) {
497 unmodified lines
modified:tests/shtest+10 added-2 removed
273 unmodified lines
274if [ -n "$($VALGRIND $Q $JQ -n 'halt_error(1)' 2>&1)" ]; then275 echo "jq halt_error(1) had unexpected output" 1>&2276 exit 1277fi278if [ -n "$($VALGRIND $Q $JQ -n '"xyz\n"|halt_error(1)' 2>/dev/null)" ]; then278if [ -n "$($VALGRIND $Q $JQ -n '"xyz\n" | halt_error(1)' 2>/dev/null)" ]; then279 echo "jq halt_error(1) had unexpected output on stdout" 1>&2280 exit 1281fi282if [ "$($VALGRIND $Q $JQ -n '"xyz\n"|halt_error(1)' 2>&1)" != "jq: error: xyz" ]; then282if [ "$($VALGRIND $Q $JQ -n '"xy" | halt_error(1)' 2>&1 || echo "z")" != "xyz" ]; then283 echo "jq halt_error(1) had unexpected output" 1>&2284 exit 1285fi286if [ "$($VALGRIND $Q $JQ -n '"x\u0000y\u0000z" | halt_error(1)' 2>&1 | tr '\0' '.')" != "x.y.z" ]; then287 echo "jq halt_error(1) had unexpected output" 1>&2288 exit 1289fi290if [ "$($VALGRIND $Q $JQ -n '{"a":"xyz"} | halt_error(1)' 2>&1)" != '{"a":"xyz"}' ]; then291 echo "jq halt_error(1) had unexpected output" 1>&2292 exit 1293fi294295# Check $JQ_COLORS296$JQ -Ccn . > $d/color297printf '\033[1;30mnull\033[0m\n' > $d/expect
52 unmodified lines