ECC-1551: grib_get: Error message does not include the offending key

This commit is contained in:
Shahram Najm 2023-03-14 21:09:57 +00:00
parent 07cd7242b7
commit 1c905d7cd3
2 changed files with 29 additions and 10 deletions

View File

@ -10,6 +10,8 @@
. ./include.ctest.sh . ./include.ctest.sh
label="grib_get_fail_test"
tempText=temp.$label.txt
REDIRECT=/dev/null REDIRECT=/dev/null
# Check input file has been downloaded # Check input file has been downloaded
@ -17,9 +19,18 @@ REDIRECT=/dev/null
# Expect failure as the key does not exist # Expect failure as the key does not exist
set +e set +e
${tools_dir}/grib_get -p gribname ${data_dir}/regular_latlon_surface.grib1 2> $REDIRECT > $REDIRECT ${tools_dir}/grib_get -p boomerang ${data_dir}/regular_latlon_surface.grib1 2> $REDIRECT > $REDIRECT
if [ $? -eq 0 ] ; then if [ $? -eq 0 ] ; then
# Should not have succeeded exit 1; # Should not have succeeded
exit 1;
fi fi
set -e
# ECC-1551: Print which key does not exist
set +e
${tools_dir}/grib_get -p Ni,Nh,Nj $ECCODES_SAMPLES_PATH/GRIB2.tmpl > $tempText 2>&1
status=$?
set -e
[ $status -ne 0 ]
grep -q "Nh (Key/value not found)" $tempText
rm -f $tempText

View File

@ -1048,7 +1048,9 @@ static void get_value_for_key(grib_handle* h, const char* key_name, int key_type
if (ret == GRIB_NOT_FOUND) { if (ret == GRIB_NOT_FOUND) {
snprintf(value_str, 32, "not_found"); snprintf(value_str, 32, "not_found");
} else { } else {
fprintf(dump_file, "ERROR: Failed to get value for key %s (%s)\n", key_name, grib_get_error_message(ret)); fprintf(dump_file, "ERROR: Failed to get value for key '%s' (%s)\n", key_name, grib_get_error_message(ret));
if (ret == GRIB_ARRAY_TOO_SMALL)
fprintf(dump_file, "\tHint: Tool %s cannot print keys of array type. Use grib_filter.\n", tool_name);
exit(1); exit(1);
} }
} }
@ -1205,12 +1207,18 @@ void grib_print_key_values(grib_runtime_options* options, grib_handle* h)
} }
if (ret != GRIB_SUCCESS) { if (ret != GRIB_SUCCESS) {
if (options->fail) if (options->fail) { // ECC-1551
GRIB_CHECK_NOLINE(ret, options->print_keys[i].name); //GRIB_CHECK_NOLINE(ret, options->print_keys[i].name);
if (ret == GRIB_NOT_FOUND) grib_context_log(h->context, GRIB_LOG_ERROR, "%s (%s)",
options->print_keys[i].name, grib_get_error_message(ret));
exit(ret);
}
if (ret == GRIB_NOT_FOUND) {
strcpy(value, notfound); strcpy(value, notfound);
else { } else {
fprintf(dump_file, "%s %s\n", grib_get_error_message(ret), options->print_keys[i].name); fprintf(dump_file, "%s (%s)\n", options->print_keys[i].name, grib_get_error_message(ret));
if (ret == GRIB_ARRAY_TOO_SMALL)
fprintf(dump_file, "\tHint: Tool %s cannot print keys of array type. Use grib_filter.\n", tool_name);
exit(ret); exit(ret);
} }
} }