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)
|
if (nomem_handler.handler)
|
||||||
nomem_handler.handler(nomem_handler.data); // Maybe handler() will longjmp() to safety
|
nomem_handler.handler(nomem_handler.data); // Maybe handler() will longjmp() to safety
|
||||||
// Or not
|
// Or not
|
||||||
fprintf(stderr, "error: cannot allocate memory\n");
|
fprintf(stderr, "jq: error: cannot allocate memory\n");
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
#else /* USE_TLS */
|
#else /* USE_TLS */
|
||||||
@@ -59,16 +59,16 @@ static void tsd_fini(void) {
|
|||||||
|
|
||||||
static void tsd_init(void) {
|
static void tsd_init(void) {
|
||||||
if (pthread_key_create(&nomem_handler_key, NULL) != 0) {
|
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();
|
abort();
|
||||||
}
|
}
|
||||||
if (atexit(tsd_fini) != 0) {
|
if (atexit(tsd_fini) != 0) {
|
||||||
fprintf(stderr, "error: cannot set an exit handler");
|
fprintf(stderr, "jq: error: cannot set an exit handler");
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
struct nomem_handler *nomem_handler = calloc(1, sizeof(struct nomem_handler));
|
struct nomem_handler *nomem_handler = calloc(1, sizeof(struct nomem_handler));
|
||||||
if (pthread_setspecific(nomem_handler_key, nomem_handler) != 0) {
|
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();
|
abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -80,7 +80,7 @@ void jv_nomem_handler(jv_nomem_handler_f handler, void *data) {
|
|||||||
nomem_handler = pthread_getspecific(nomem_handler_key);
|
nomem_handler = pthread_getspecific(nomem_handler_key);
|
||||||
if (nomem_handler == NULL) {
|
if (nomem_handler == NULL) {
|
||||||
handler(data);
|
handler(data);
|
||||||
fprintf(stderr, "error: cannot allocate memory\n");
|
fprintf(stderr, "jq: error: cannot allocate memory\n");
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
nomem_handler->handler = handler;
|
nomem_handler->handler = handler;
|
||||||
@@ -95,7 +95,7 @@ static void memory_exhausted() {
|
|||||||
if (nomem_handler)
|
if (nomem_handler)
|
||||||
nomem_handler->handler(nomem_handler->data); // Maybe handler() will longjmp() to safety
|
nomem_handler->handler(nomem_handler->data); // Maybe handler() will longjmp() to safety
|
||||||
// Or not
|
// Or not
|
||||||
fprintf(stderr, "error: cannot allocate memory\n");
|
fprintf(stderr, "jq: error: cannot allocate memory\n");
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +110,7 @@ void jv_nomem_handler(jv_nomem_handler_f handler, void *data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void memory_exhausted() {
|
static void memory_exhausted() {
|
||||||
fprintf(stderr, "error: cannot allocate memory\n");
|
fprintf(stderr, "jq: error: cannot allocate memory\n");
|
||||||
abort();
|
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_free(exit_code);
|
||||||
jv error_message = jq_get_error_message(jq);
|
jv error_message = jq_get_error_message(jq);
|
||||||
if (jv_get_kind(error_message) == JV_KIND_STRING) {
|
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) {
|
} else if (jv_get_kind(error_message) == JV_KIND_NULL) {
|
||||||
// Halt with no output
|
// Halt with no output
|
||||||
} else if (jv_is_valid(error_message)) {
|
} else if (jv_is_valid(error_message)) {
|
||||||
error_message = jv_dump_string(jv_copy(error_message), 0);
|
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
|
} // else no message on stderr; use --debug-trace to see a message
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
jv_free(error_message);
|
jv_free(error_message);
|
||||||
@@ -586,7 +586,7 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
char *origin = strdup(argv[0]);
|
char *origin = strdup(argv[0]);
|
||||||
if (origin == NULL) {
|
if (origin == NULL) {
|
||||||
fprintf(stderr, "Error: out of memory\n");
|
fprintf(stderr, "jq: error: out of memory\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
jq_set_attr(jq, jv_string("JQ_ORIGIN"), jv_string(dirname(origin)));
|
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)) {
|
if (!(options & SEQ)) {
|
||||||
// --seq -> errors are not fatal
|
// --seq -> errors are not fatal
|
||||||
ret = JQ_OK_NO_OUTPUT;
|
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);
|
jv_free(msg);
|
||||||
break;
|
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);
|
jv_free(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -693,7 +693,7 @@ int main(int argc, char* argv[]) {
|
|||||||
out:
|
out:
|
||||||
badwrite = ferror(stdout);
|
badwrite = ferror(stdout);
|
||||||
if (fclose(stdout)!=0 || badwrite) {
|
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;
|
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).
|
// 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
|
// TODO: report it. Can't use 'state->err_cb()' as it is hard-coded for
|
||||||
// 'open' related problems.
|
// '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) {
|
||||||
if (state->current_input == stdin) {
|
if (state->current_input == stdin) {
|
||||||
|
Reference in New Issue
Block a user