From 44cb31cfd1c1b64cbb3a702b2d9f2e05a1e94c3d Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Tue, 8 Aug 2023 13:16:05 +0100 Subject: [PATCH] Tools: Test for error conditions --- tests/grib_ls.sh | 11 +++++++++++ tools/grib_tools.cc | 3 +-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/grib_ls.sh b/tests/grib_ls.sh index b9a3d7b4b..29ede3bcf 100755 --- a/tests/grib_ls.sh +++ b/tests/grib_ls.sh @@ -191,5 +191,16 @@ set -e [ $status -ne 0 ] grep -q "Invalid type for key=shortName" $tempText +# Do list after an offset +file=tigge_pf_ecmwf.grib2 +${tools_dir}/grib_ls -X 62414 $file +set +e +${tools_dir}/grib_ls -X -1 $file > $tempText 2>&1 +status=$? +set -e +[ $status -ne 0 ] +grep -q "Invalid file offset" $tempText + + # Clean up rm -f $temp1 $temp2 $tempText $tempLog diff --git a/tools/grib_tools.cc b/tools/grib_tools.cc index 8b6becee7..51e918ec4 100644 --- a/tools/grib_tools.cc +++ b/tools/grib_tools.cc @@ -343,8 +343,7 @@ static int grib_tool_without_orderby(grib_runtime_options* options) #endif err = fseeko(infile->file, options->infile_offset, SEEK_SET); if (err) { - /*fprintf(stderr, "Invalid file offset: %ld\n", options->infile_offset);*/ - perror("Invalid file offset"); + fprintf(stderr, "%s: Invalid file offset: %lld\n", tool_name, options->infile_offset); exit(1); } }