Add better error messages

This commit is contained in:
Shahram Najm 2023-09-22 13:04:58 +01:00
parent ee77c57a5d
commit 571b894019
4 changed files with 22 additions and 12 deletions

View File

@ -469,7 +469,10 @@ static int pack_long(grib_accessor* a, const long* v, size_t* len)
grib_context_free(c, val);
return ret;
}
grib_context_log(c, GRIB_LOG_ERROR, "Should not grib_pack %s as long", a->name);
grib_context_log(c, GRIB_LOG_ERROR, "Should not pack '%s' as an integer", a->name);
if (a->cclass->pack_string && a->cclass->pack_string != &pack_string) {
grib_context_log(c, GRIB_LOG_ERROR, "Try packing as a string");
}
return GRIB_NOT_IMPLEMENTED;
}
@ -507,7 +510,10 @@ static int pack_double(grib_accessor* a, const double* v, size_t* len)
if (do_pack_as_long) {
return pack_double_array_as_long(a, v, len);
}
grib_context_log(c, GRIB_LOG_ERROR, "Should not grib_pack %s as double", a->name);
grib_context_log(c, GRIB_LOG_ERROR, "Should not pack '%s' as a double", a->name);
if (a->cclass->pack_string && a->cclass->pack_string != &pack_string) {
grib_context_log(c, GRIB_LOG_ERROR, "Try packing as a string");
}
return GRIB_NOT_IMPLEMENTED;
}

View File

@ -7,9 +7,6 @@
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
/***********************************************************
* Enrico Fucile
***********************************************************/
#include "grib_api_internal.h"
/*
@ -181,13 +178,13 @@ static int pack_string(grib_accessor* a, const char* val, size_t* len)
static int pack_long(grib_accessor* a, const long* v, size_t* len)
{
grib_context_log(a->context, GRIB_LOG_ERROR, " Should not pack %s as long", a->name);
grib_context_log(a->context, GRIB_LOG_ERROR, "Should not pack %s as an integer", a->name);
return GRIB_NOT_IMPLEMENTED;
}
static int pack_double(grib_accessor* a, const double* v, size_t* len)
{
grib_context_log(a->context, GRIB_LOG_ERROR, " Should not pack %s as double", a->name);
grib_context_log(a->context, GRIB_LOG_ERROR, "Should not pack %s as a double", a->name);
return GRIB_NOT_IMPLEMENTED;
}

View File

@ -7,9 +7,6 @@
* In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
* virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
*/
/***********************************************************
* Enrico Fucile
***********************************************************/
#include "grib_api_internal.h"
/*
@ -206,13 +203,13 @@ static int pack_string(grib_accessor* a, const char* val, size_t* len)
static int pack_long(grib_accessor* a, const long* v, size_t* len)
{
grib_context_log(a->context, GRIB_LOG_ERROR, " Should not pack %s as long", a->name);
grib_context_log(a->context, GRIB_LOG_ERROR, "Should not pack %s as an integer", a->name);
return GRIB_NOT_IMPLEMENTED;
}
static int pack_double(grib_accessor* a, const double* v, size_t* len)
{
grib_context_log(a->context, GRIB_LOG_ERROR, " Should not pack %s as double", a->name);
grib_context_log(a->context, GRIB_LOG_ERROR, "Should not pack %s as a double", a->name);
return GRIB_NOT_IMPLEMENTED;
}

View File

@ -32,6 +32,7 @@ grib_check_key_equals $temp2 uuidOfHGrid '10991111111111111111115000110000'
# Test errors
# --------------
set +e
# Invalid HEX
${tools_dir}/grib_set -s uuidOfHGrid=DEZZBEef10203040b00b1e50001100FF $temp1 $temp2 2>$errlog
@ -40,6 +41,15 @@ set -e
[ $status -ne 0 ]
grep -q "Invalid hex byte specfication 'ZZ'" $errlog
# Packing as an integer
set +e
${tools_dir}/grib_set -s uuidOfHGrid=12345 $temp1 $temp2 2>$errlog
status=$?
set -e
[ $status -ne 0 ]
grep -q "Should not pack 'uuidOfHGrid' as an integer" $errlog
grep -q "Try packing as a string" $errlog
# Clean up
rm -f $temp1 $temp2 $errlog