From 9f31ef8a394b66a6d631bbc76f85d99dea624eb7 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 25 Jul 2024 10:55:06 +0000 Subject: [PATCH] ECC-1883: Better error message when accessor not found --- src/grib_value.cc | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/grib_value.cc b/src/grib_value.cc index 32c637964..51a839da4 100644 --- a/src/grib_value.cc +++ b/src/grib_value.cc @@ -62,6 +62,18 @@ static void print_debug_info__set_array(grib_handle* h, const char* func, const fprintf(stderr, "min=%.10g, max=%.10g\n",minVal,maxVal); } +static void print_error_no_accessor(const grib_context* c, const char* name) +{ + grib_context_log(c, GRIB_LOG_ERROR, "Unable to find accessor %s", name); + const char* dpath = getenv("ECCODES_DEFINITION_PATH"); + if (dpath != NULL) { + grib_context_log(c, GRIB_LOG_ERROR, + "Hint: This could be a symptom of an issue with your definitions.\n\t" + "The environment variable ECCODES_DEFINITION_PATH is defined and set to '%s'.\n\t" + "Please use the latest definitions.", dpath); + } +} + int grib_set_expression(grib_handle* h, const char* name, grib_expression* e) { grib_accessor* a = grib_find_accessor(h, name); @@ -103,7 +115,8 @@ int grib_set_long_internal(grib_handle* h, const char* name, long val) return ret; } - grib_context_log(c, GRIB_LOG_ERROR, "Unable to find accessor %s", name); + print_error_no_accessor(c, name); + //grib_context_log(c, GRIB_LOG_ERROR, "Unable to find accessor %s", name); return GRIB_NOT_FOUND; } @@ -162,7 +175,8 @@ int grib_set_double_internal(grib_handle* h, const char* name, double val) return ret; } - grib_context_log(h->context, GRIB_LOG_ERROR, "Unable to find accessor %s", name); + print_error_no_accessor(h->context, name); + //grib_context_log(h->context, GRIB_LOG_ERROR, "Unable to find accessor %s", name); return GRIB_NOT_FOUND; } @@ -389,7 +403,8 @@ int grib_set_string_internal(grib_handle* h, const char* name, return ret; } - grib_context_log(h->context, GRIB_LOG_ERROR, "Unable to find accessor %s", name); + print_error_no_accessor(h->context, name); + //grib_context_log(h->context, GRIB_LOG_ERROR, "Unable to find accessor %s", name); return GRIB_NOT_FOUND; }