Tools: Improved error messages

This commit is contained in:
Shahram Najm 2023-12-06 12:57:07 +00:00
parent bfabfb2e21
commit 937d2fa737
7 changed files with 13 additions and 10 deletions

View File

@ -1815,9 +1815,9 @@ int grib_set_values(grib_handle* h, grib_values* args, size_t count)
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
if (args[i].error != GRIB_SUCCESS) { if (args[i].error != GRIB_SUCCESS) {
grib_context_log(h->context, GRIB_LOG_ERROR, 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), 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; err = err == GRIB_SUCCESS ? args[i].error : err;
} }
} }

View File

@ -36,7 +36,7 @@ EOF
# Command should fail but not crash # Command should fail but not crash
set +e set +e
${tools_dir}/bufr_filter $tempFilt $sample_bufr4 > $tempOut ${tools_dir}/bufr_filter $tempFilt $sample_bufr4 2> $tempOut
stat=$? stat=$?
set -e set -e
echo stat=$stat echo stat=$stat

View File

@ -365,7 +365,7 @@ cat >$tempFilt <<EOF
assert(edition == 0); assert(edition == 0);
EOF EOF
set +e set +e
${tools_dir}/grib_filter $tempFilt $ECCODES_SAMPLES_PATH/GRIB2.tmpl > $tempOut ${tools_dir}/grib_filter $tempFilt $ECCODES_SAMPLES_PATH/GRIB2.tmpl 2> $tempOut
status=$? status=$?
set -e set -e
[ $status -ne 0 ] [ $status -ne 0 ]

View File

@ -34,6 +34,7 @@ cat > $tempRef <<EOF
ECCODES ERROR : key 'a_deprecated_key' is unavailable in this version. ECCODES ERROR : key 'a_deprecated_key' is unavailable in this version.
ECCODES ERROR : Please use the following key(s): ECCODES ERROR : Please use the following key(s):
ECCODES ERROR : - typeOfOriginalFieldValues ECCODES ERROR : - typeOfOriginalFieldValues
ERROR: Key/value not found (message 1)
EOF EOF
diff $tempRef $tempErr diff $tempRef $tempErr

View File

@ -53,7 +53,7 @@ int grib_tool_init(grib_runtime_options* options)
if (!options->action) { if (!options->action) {
const char* filt = options->infile_extra->name; const char* filt = options->infile_extra->name;
if (strcmp(filt, "-") == 0) filt = "stdin"; 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); 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); err = grib_handle_apply_action(h, options->action);
if (err != GRIB_SUCCESS && options->fail) { 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); exit(err);
} }
return 0; return 0;

View File

@ -62,7 +62,7 @@ int grib_tool_before_getopt(grib_runtime_options* options)
int grib_tool_init(grib_runtime_options* options) int grib_tool_init(grib_runtime_options* options)
{ {
if (options->set_values_count == 0 && !options->repack && !options->constant) { 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); exit(1);
} }
if (options->verbose) if (options->verbose)
@ -73,7 +73,7 @@ int grib_tool_init(grib_runtime_options* options)
}*/ }*/
if (grib_options_on("n:") && grib_options_on("d:")) { 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); exit(1);
} }

View File

@ -54,7 +54,7 @@ int grib_tool_init(grib_runtime_options* options)
if (!options->action) { if (!options->action) {
const char* filt = options->infile_extra->name; const char* filt = options->infile_extra->name;
if (strcmp(filt, "-") == 0) filt = "stdin"; 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); 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); err = grib_handle_apply_action(h, options->action);
if (err != GRIB_SUCCESS && options->fail) { 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); exit(err);
} }
return 0; return 0;