diff options
author | Nicolas Williams <nico@cryptonector.com> | 2019-03-24 23:32:42 -0500 |
---|---|---|
committer | Nicolas Williams <nico@cryptonector.com> | 2019-03-24 23:36:18 -0500 |
commit | 2b4d51f6976f15307e70387d3e015de274589193 (patch) | |
tree | a4d4c37439c4b0cc8519da3cf4b08c25008cc9d7 | |
parent | 0dab2b18d73e561f5118011a65cc9877bf21c110 (diff) |
Identify progname in more errors (fix #1860)
However, we should really use the argv[0] progname, not just jq.
Someday we may want to support aliases which automatically add certain
options, etc.
-rw-r--r-- | src/jv_alloc.c | 14 | ||||
-rw-r--r-- | src/main.c | 12 | ||||
-rw-r--r-- | src/util.c | 2 |
3 files changed, 14 insertions, 14 deletions
diff --git a/src/jv_alloc.c b/src/jv_alloc.c index fd7b2579..5fa67684 100644 --- a/src/jv_alloc.c +++ b/src/jv_alloc.c @@ -37,7 +37,7 @@ static void memory_exhausted() { if (nomem_handler.handler) nomem_handler.handler(nomem_handler.data); // Maybe handler() will longjmp() to safety // Or not - fprintf(stderr, "error: cannot allocate memory\n"); + fprintf(stderr, "jq: error: cannot allocate memory\n"); abort(); } #else /* USE_TLS */ @@ -59,16 +59,16 @@ static void tsd_fini(void) { static void tsd_init(void) { if (pthread_key_create(&nomem_handler_key, NULL) != 0) { - fprintf(stderr, "error: cannot create thread specific key"); + fprintf(stderr, "jq: error: cannot create thread specific key"); abort(); } if (atexit(tsd_fini) != 0) { - fprintf(stderr, "error: cannot set an exit handler"); + fprintf(stderr, "jq: error: cannot set an exit handler"); abort(); } struct nomem_handler *nomem_handler = calloc(1, sizeof(struct nomem_handler)); if (pthread_setspecific(nomem_handler_key, nomem_handler) != 0) { - fprintf(stderr, "error: cannot set thread specific data"); + fprintf(stderr, "jq: error: cannot set thread specific data"); abort(); } } @@ -80,7 +80,7 @@ void jv_nomem_handler(jv_nomem_handler_f handler, void *data) { nomem_handler = pthread_getspecific(nomem_handler_key); if (nomem_handler == NULL) { handler(data); - fprintf(stderr, "error: cannot allocate memory\n"); + fprintf(stderr, "jq: error: cannot allocate memory\n"); abort(); } nomem_handler->handler = handler; @@ -95,7 +95,7 @@ static void memory_exhausted() { if (nomem_handler) nomem_handler->handler(nomem_handler->data); // Maybe handler() will longjmp() to safety // Or not - fprintf(stderr, "error: cannot allocate memory\n"); + fprintf(stderr, "jq: error: cannot allocate memory\n"); abort(); } @@ -110,7 +110,7 @@ void jv_nomem_handler(jv_nomem_handler_f handler, void *data) { } static void memory_exhausted() { - fprintf(stderr, "error: cannot allocate memory\n"); + fprintf(stderr, "jq: error: cannot allocate memory\n"); abort(); } @@ -212,12 +212,12 @@ 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, "%s", jv_string_value(error_message)); + fprintf(stderr, "jq: error: %s", jv_string_value(error_message)); } 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, "%s\n", jv_string_value(error_message)); + fprintf(stderr, "jq: error: %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); @@ -586,7 +586,7 @@ int main(int argc, char* argv[]) { char *origin = strdup(argv[0]); if (origin == NULL) { - fprintf(stderr, "Error: out of memory\n"); + fprintf(stderr, "jq: error: out of memory\n"); exit(1); } jq_set_attr(jq, jv_string("JQ_ORIGIN"), jv_string(dirname(origin))); @@ -678,11 +678,11 @@ int main(int argc, char* argv[]) { if (!(options & SEQ)) { // --seq -> errors are not fatal ret = JQ_OK_NO_OUTPUT; - fprintf(stderr, "parse error: %s\n", jv_string_value(msg)); + fprintf(stderr, "jq: parse error: %s\n", jv_string_value(msg)); jv_free(msg); break; } - fprintf(stderr, "ignoring parse error: %s\n", jv_string_value(msg)); + fprintf(stderr, "jq: ignoring parse error: %s\n", jv_string_value(msg)); jv_free(msg); } } @@ -693,7 +693,7 @@ int main(int argc, char* argv[]) { out: badwrite = ferror(stdout); if (fclose(stdout)!=0 || badwrite) { - fprintf(stderr,"Error: writing output failed: %s\n", strerror(errno)); + fprintf(stderr,"jq: error: writing output failed: %s\n", strerror(errno)); ret = JQ_ERROR_SYSTEM; } @@ -275,7 +275,7 @@ static int jq_util_input_read_more(jq_util_input_state *state) { // System-level input error on the stream. It will be closed (below). // TODO: report it. Can't use 'state->err_cb()' as it is hard-coded for // 'open' related problems. - fprintf(stderr,"Input error: %s\n", strerror(errno)); + fprintf(stderr,"jq: error: %s\n", strerror(errno)); } if (state->current_input) { if (state->current_input == stdin) { |