Skip to content

Commit

Permalink
Identify progname in more errors (fix jqlang#1860)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nicowilliams committed Mar 25, 2019
1 parent 0dab2b1 commit 2b4d51f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions src/jv_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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();
}
}
Expand All @@ -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;
Expand All @@ -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();
}

Expand All @@ -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();
}

Expand Down
12 changes: 6 additions & 6 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)));
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 2b4d51f

Please sign in to comment.