mirror of
https://github.com/stedolan/jq.git
synced 2024-05-11 05:55:39 +00:00
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.
This commit is contained in:
@ -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();
|
||||
}
|
||||
|
||||
|
12
src/main.c
12
src/main.c
@ -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) {
|
||||
|
Reference in New Issue
Block a user