From a4d0f05a43237dce7fa71389e46eac27943f7754 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Sun, 9 Apr 2023 12:45:01 +0100 Subject: [PATCH] Better error messages --- src/grib_accessor_class_bitmap.cc | 9 +++------ src/grib_accessor_class_g2level.cc | 2 +- src/grib_accessor_class_global_gaussian.cc | 6 +++--- src/grib_accessor_class_time.cc | 4 ++-- tools/CMakeLists.txt | 4 +++- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/grib_accessor_class_bitmap.cc b/src/grib_accessor_class_bitmap.cc index 5a16b0ef1..31c5997d6 100644 --- a/src/grib_accessor_class_bitmap.cc +++ b/src/grib_accessor_class_bitmap.cc @@ -178,10 +178,7 @@ static void compute_size(grib_accessor* a) } } -#if 0 - printf("compute_size off=%ld slen=%ld a->offset=%ld\n", - (long)off,(long)slen,(long)a->offset); -#endif + // printf("compute_size off=%ld slen=%ld a->offset=%ld\n", (long)off,(long)slen,(long)a->offset); a->length = off + (slen - a->offset); @@ -237,7 +234,7 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) return err; if (*len < tlen) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s it contains %ld values", a->name, tlen); + grib_context_log(a->context, GRIB_LOG_ERROR, "Wrong size for %s, it contains %ld values", a->name, tlen); *len = 0; return GRIB_ARRAY_TOO_SMALL; } @@ -315,7 +312,7 @@ static int unpack_string(grib_accessor* a, char* val, size_t* len) grib_handle* hand = grib_handle_of_accessor(a); if (len[0] < (a->length)) { - grib_context_log(a->context, GRIB_LOG_ERROR, "unpack_string: Wrong size (%lu) for %s it contains %ld values", + grib_context_log(a->context, GRIB_LOG_ERROR, "unpack_string: Wrong size (%lu) for %s, it contains %ld values", len[0], a->name, a->length); len[0] = 0; return GRIB_ARRAY_TOO_SMALL; diff --git a/src/grib_accessor_class_g2level.cc b/src/grib_accessor_class_g2level.cc index 0831bb9e2..d0ae0571c 100644 --- a/src/grib_accessor_class_g2level.cc +++ b/src/grib_accessor_class_g2level.cc @@ -296,7 +296,7 @@ static int pack_double(grib_accessor* a, const double* val, size_t* len) ret = compute_scaled_value_and_scale_factor(value_first, scaled_value_max, scale_factor_max, &lscaled_value, &lscale_factor); if (ret) { - grib_context_log(a->context, GRIB_LOG_ERROR, "Accessor %s: Failed to compute %s and %s from %g", + grib_context_log(a->context, GRIB_LOG_ERROR, "Key %s (unpack_double): Failed to compute %s and %s from %g", a->name, self->scale_first, self->value_first, value_first); return ret; } diff --git a/src/grib_accessor_class_global_gaussian.cc b/src/grib_accessor_class_global_gaussian.cc index d36c2a59b..90d69655b 100644 --- a/src/grib_accessor_class_global_gaussian.cc +++ b/src/grib_accessor_class_global_gaussian.cc @@ -240,14 +240,14 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) dlonlast = ((double)lonlast) / factor; if (N == 0) { - grib_context_log(c, GRIB_LOG_ERROR, "global_gaussian unpack_long: N cannot be 0!"); + grib_context_log(c, GRIB_LOG_ERROR, "Key %s (unpack_long): N cannot be 0!", a->name); return GRIB_WRONG_GRID; } lats = (double*)grib_context_malloc(c, sizeof(double) * N * 2); if (!lats) { grib_context_log(c, GRIB_LOG_ERROR, - "global_gaussian unpack_long: Memory allocation error: %ld bytes", sizeof(double) * N * 2); + "Key %s (unpack_long): Memory allocation error: %zu bytes", a->name, sizeof(double) * N * 2); return GRIB_OUT_OF_MEMORY; } if ((ret = grib_get_gaussian_latitudes(N, lats)) != GRIB_SUCCESS) @@ -333,7 +333,7 @@ static int pack_long(grib_accessor* a, const long* val, size_t* len) lats = (double*)grib_context_malloc(c, sizeof(double) * N * 2); if (!lats) { grib_context_log(c, GRIB_LOG_ERROR, - "global_gaussian pack_long: Memory allocation error: %zu bytes", sizeof(double) * N * 2); + "Key %s (pack_long): Memory allocation error: %zu bytes", a->name, sizeof(double) * N * 2); return GRIB_OUT_OF_MEMORY; } if ((ret = grib_get_gaussian_latitudes(N, lats)) != GRIB_SUCCESS) diff --git a/src/grib_accessor_class_time.cc b/src/grib_accessor_class_time.cc index 1bdfdec7b..e163ff66f 100644 --- a/src/grib_accessor_class_time.cc +++ b/src/grib_accessor_class_time.cc @@ -182,7 +182,7 @@ static int unpack_long(grib_accessor* a, long* val, size_t* len) /* We ignore the 'seconds' in our time calculation! */ if (second != 0) { grib_context_log(a->context, GRIB_LOG_ERROR, - "Truncating time: non-zero seconds(%ld) ignored", second); + "Key %s (unpack_long): Truncating time: non-zero seconds(%ld) ignored", a->name, second); } if (*len < 1) @@ -236,7 +236,7 @@ static int unpack_string(grib_accessor* a, char* val, size_t* len) unpack_long(a, &v, &lsize); if (*len < 5) { - grib_context_log(a->context, GRIB_LOG_ERROR, "grib_accessor_time : unpack_string : Buffer too small for %s", a->name); + grib_context_log(a->context, GRIB_LOG_ERROR, "Key %s (unpack_string): Buffer too small", a->name); *len = 5; return GRIB_BUFFER_TOO_SMALL; diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 45818a0e8..e9b3d4af9 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -91,15 +91,17 @@ ecbuild_add_executable( TARGET codes_bufr_filter LIBS ecc_tools ) -# grib1to2 script needs to be generated before installation if( ECCODES_INSTALL_EXTRA_TOOLS ) ecbuild_info("ECCODES_INSTALL_EXTRA_TOOLS enabled") + # grib1to2 script needs to be generated before installation configure_file( grib1to2.in grib1to2 ) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/grib1to2 DESTINATION ${INSTALL_BIN_DIR} PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_EXECUTE WORLD_READ ) +else() + ecbuild_info("ECCODES_INSTALL_EXTRA_TOOLS disabled") endif() ########################################