From 937d2fa737cf567ed4237b756a6bb034f9126644 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Wed, 6 Dec 2023 12:57:07 +0000 Subject: [PATCH] Tools: Improved error messages --- src/grib_value.cc | 4 ++-- tests/bufr_ecc-1304.sh | 2 +- tests/grib_filter.sh | 2 +- tests/grib_suppressed.sh | 1 + tools/bufr_filter.cc | 5 +++-- tools/bufr_set.cc | 4 ++-- tools/grib_filter.cc | 5 +++-- 7 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/grib_value.cc b/src/grib_value.cc index e244d3c65..f9e24d678 100644 --- a/src/grib_value.cc +++ b/src/grib_value.cc @@ -1815,9 +1815,9 @@ int grib_set_values(grib_handle* h, grib_values* args, size_t count) for (i = 0; i < count; i++) { if (args[i].error != GRIB_SUCCESS) { grib_context_log(h->context, GRIB_LOG_ERROR, - "grib_set_values[%d] %s (type=%s) failed: %s", + "grib_set_values[%d] %s (type=%s) failed: %s (message %d)", i, args[i].name, grib_get_type_name(args[i].type), - grib_get_error_message(args[i].error)); + grib_get_error_message(args[i].error), h->context->handle_file_count); err = err == GRIB_SUCCESS ? args[i].error : err; } } diff --git a/tests/bufr_ecc-1304.sh b/tests/bufr_ecc-1304.sh index 2ffd34711..4e1bc409f 100755 --- a/tests/bufr_ecc-1304.sh +++ b/tests/bufr_ecc-1304.sh @@ -36,7 +36,7 @@ EOF # Command should fail but not crash set +e -${tools_dir}/bufr_filter $tempFilt $sample_bufr4 > $tempOut +${tools_dir}/bufr_filter $tempFilt $sample_bufr4 2> $tempOut stat=$? set -e echo stat=$stat diff --git a/tests/grib_filter.sh b/tests/grib_filter.sh index c114c5e4e..1010cd9e0 100755 --- a/tests/grib_filter.sh +++ b/tests/grib_filter.sh @@ -365,7 +365,7 @@ cat >$tempFilt < $tempOut +${tools_dir}/grib_filter $tempFilt $ECCODES_SAMPLES_PATH/GRIB2.tmpl 2> $tempOut status=$? set -e [ $status -ne 0 ] diff --git a/tests/grib_suppressed.sh b/tests/grib_suppressed.sh index c8166ebce..2b8477064 100755 --- a/tests/grib_suppressed.sh +++ b/tests/grib_suppressed.sh @@ -34,6 +34,7 @@ cat > $tempRef <action) { const char* filt = options->infile_extra->name; if (strcmp(filt, "-") == 0) filt = "stdin"; - fprintf(stderr, "Error: %s: unable to create action\n", filt); + fprintf(stderr, "ERROR: %s: unable to create action\n", filt); exit(1); } @@ -88,7 +88,8 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h) err = grib_handle_apply_action(h, options->action); if (err != GRIB_SUCCESS && options->fail) { - printf("ERROR: %s\n", grib_get_error_message(err)); + fprintf(stderr, "ERROR: %s (message %d)\n", + grib_get_error_message(err), h->context->handle_file_count); exit(err); } return 0; diff --git a/tools/bufr_set.cc b/tools/bufr_set.cc index 40c51547b..4bb055fb9 100644 --- a/tools/bufr_set.cc +++ b/tools/bufr_set.cc @@ -62,7 +62,7 @@ int grib_tool_before_getopt(grib_runtime_options* options) int grib_tool_init(grib_runtime_options* options) { if (options->set_values_count == 0 && !options->repack && !options->constant) { - printf("ERROR: please provide some keys to set through the -s option or use the -r/-d options\n"); + fprintf(stderr, "ERROR: Please provide some keys to set through the -s option or use the -r/-d options\n"); exit(1); } if (options->verbose) @@ -73,7 +73,7 @@ int grib_tool_init(grib_runtime_options* options) }*/ if (grib_options_on("n:") && grib_options_on("d:")) { - printf("Error: -n and -d options are incompatible. Choose one of the two please.\n"); + fprintf(stderr, "ERROR: -n and -d options are incompatible. Choose one of the two please.\n"); exit(1); } diff --git a/tools/grib_filter.cc b/tools/grib_filter.cc index 019fc48c8..ae0a1c5e3 100644 --- a/tools/grib_filter.cc +++ b/tools/grib_filter.cc @@ -54,7 +54,7 @@ int grib_tool_init(grib_runtime_options* options) if (!options->action) { const char* filt = options->infile_extra->name; if (strcmp(filt, "-") == 0) filt = "stdin"; - fprintf(stderr, "Error: %s: unable to create action\n", filt); + fprintf(stderr, "ERROR: %s: unable to create action\n", filt); exit(1); } @@ -86,7 +86,8 @@ int grib_tool_new_handle_action(grib_runtime_options* options, grib_handle* h) err = grib_handle_apply_action(h, options->action); if (err != GRIB_SUCCESS && options->fail) { - printf("ERROR: %s\n", grib_get_error_message(err)); + fprintf(stderr, "ERROR: %s (message %d)\n", + grib_get_error_message(err), h->context->handle_file_count); exit(err); } return 0;