Skip to content

Commit

Permalink
Merge pull request #3054 from rouault/fix_3051
Browse files Browse the repository at this point in the history
Report dataset name in error messages (AAIGRID, GTiff)
  • Loading branch information
rouault authored Oct 13, 2020
2 parents f5e5738 + dc58b6e commit f999a23
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 178 deletions.
2 changes: 1 addition & 1 deletion autotest/gcore/basic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ def test_basic_test_16():
with gdaltest.error_handler():
gdal.OpenEx('/vsimem/temp.tif', gdal.OF_UPDATE, open_options=['@NUM_THREADS=INVALID'])
gdal.Unlink('/vsimem/temp.tif')
assert gdal.GetLastErrorMsg() == 'Invalid value for NUM_THREADS: INVALID'
assert 'Invalid value for NUM_THREADS: INVALID' in gdal.GetLastErrorMsg()

###############################################################################
# Test mix of gdal/ogr.UseExceptions()/DontUseExceptions()
Expand Down
4 changes: 2 additions & 2 deletions autotest/gcore/tiff_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -7184,7 +7184,7 @@ def test_tiff_write_overviews_mask_no_ovr_on_mask():
gdal.ErrorReset()
with gdaltest.error_handler():
ds.BuildOverviews('NEAR', overviewlist=[2])
assert gdal.GetLastErrorMsg() == 'Building external overviews whereas there is an internal mask is not fully supported. The overviews of the non-mask bands will be created, but not the overviews of the mask band.'
assert 'Building external overviews whereas there is an internal mask is not fully supported. The overviews of the non-mask bands will be created, but not the overviews of the mask band.' in gdal.GetLastErrorMsg()
# No overview on the mask
assert ds.GetRasterBand(1).GetOverview(0).GetMaskFlags() == gdal.GMF_ALL_VALID
ds = None
Expand All @@ -7194,7 +7194,7 @@ def test_tiff_write_overviews_mask_no_ovr_on_mask():
gdal.ErrorReset()
with gdaltest.error_handler():
ds = gdaltest.tiff_drv.CreateCopy(tmpfile2, src_ds, options=['COPY_SRC_OVERVIEWS=YES'])
assert gdal.GetLastErrorMsg() == 'Source dataset has a mask band on full resolution, overviews on the regular bands, but lacks overviews on the mask band.'
assert 'Source dataset has a mask band on full resolution, overviews on the regular bands, but lacks overviews on the mask band.' in gdal.GetLastErrorMsg()
assert ds
ds = None
src_ds = None
Expand Down
54 changes: 28 additions & 26 deletions gdal/frmts/aaigrid/aaigriddataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ CPLErr AAIGRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,

if( poODS->Seek(panLineOffset[nBlockYOff]) != 0 )
{
CPLError(CE_Failure, CPLE_FileIO,
ReportError(CE_Failure, CPLE_FileIO,
"Can't seek to offset %lu in input file to read data.",
static_cast<long unsigned int>(panLineOffset[nBlockYOff]));
return CE_Failure;
Expand All @@ -171,7 +171,7 @@ CPLErr AAIGRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
{
if( iTokenChar == sizeof(szToken) - 2 )
{
CPLError(CE_Failure, CPLE_FileIO,
ReportError(CE_Failure, CPLE_FileIO,
"Token too long at scanline %d.", nBlockYOff);
return CE_Failure;
}
Expand All @@ -184,7 +184,7 @@ CPLErr AAIGRasterBand::IReadBlock( int nBlockXOff, int nBlockYOff,
(iPixel != poODS->nRasterXSize - 1 ||
nBlockYOff != poODS->nRasterYSize - 1) )
{
CPLError(CE_Failure, CPLE_FileIO, "File short, can't read line %d.",
ReportError(CE_Failure, CPLE_FileIO, "File short, can't read line %d.",
nBlockYOff);
return CE_Failure;
}
Expand Down Expand Up @@ -284,7 +284,7 @@ AAIGDataset::~AAIGDataset()
{
if( VSIFCloseL(fp) != 0 )
{
CPLError(CE_Failure, CPLE_FileIO, "I/O error");
ReportError(CE_Failure, CPLE_FileIO, "I/O error");
}
}

Expand Down Expand Up @@ -694,7 +694,7 @@ int GRASSASCIIDataset::ParseHeader(const char *pszHeader,
eDataType = GDT_Float64;
else
{
CPLError(CE_Warning, CPLE_AppDefined,
ReportError(CE_Warning, CPLE_AppDefined,
"Invalid value for type parameter : %s", pszType);
}
}
Expand Down Expand Up @@ -926,9 +926,10 @@ GDALDataset *AAIGDataset::CommonOpen( GDALOpenInfo *poOpenInfo,
if (!(poDS->eDataType == GDT_Int32 || poDS->eDataType == GDT_Float32 ||
poDS->eDataType == GDT_Float64))
{
CPLError(CE_Warning, CPLE_NotSupported,
"Unsupported value for %s : %s",
pszDataTypeOption, pszDataType);
ReportError(poOpenInfo->pszFilename,
CE_Warning, CPLE_NotSupported,
"Unsupported value for %s : %s",
pszDataTypeOption, pszDataType);
poDS->eDataType = GDT_Int32;
pszDataType = nullptr;
}
Expand Down Expand Up @@ -986,8 +987,9 @@ GDALDataset *AAIGDataset::CommonOpen( GDALOpenInfo *poOpenInfo,
{
if( poOpenInfo->pabyHeader[i] == '\0' )
{
CPLError(CE_Failure, CPLE_AppDefined,
"Couldn't find data values in ASCII Grid file.");
ReportError(poOpenInfo->pszFilename,
CE_Failure, CPLE_AppDefined,
"Couldn't find data values in ASCII Grid file.");
delete poDS;
return nullptr;
}
Expand Down Expand Up @@ -1161,9 +1163,9 @@ GDALDataset * AAIGDataset::CreateCopy(
// Some rudimentary checks.
if( nBands != 1 )
{
CPLError(CE_Failure, CPLE_NotSupported,
"AAIG driver doesn't support %d bands. Must be 1 band.",
nBands);
ReportError(pszFilename, CE_Failure, CPLE_NotSupported,
"AAIG driver doesn't support %d bands. Must be 1 band.",
nBands);

return nullptr;
}
Expand All @@ -1175,9 +1177,8 @@ GDALDataset * AAIGDataset::CreateCopy(
VSILFILE *fpImage = VSIFOpenL(pszFilename, "wt");
if( fpImage == nullptr )
{
CPLError(CE_Failure, CPLE_OpenFailed,
"Unable to create file %s.",
pszFilename);
ReportError(pszFilename, CE_Failure, CPLE_OpenFailed,
"Unable to create file.");
return nullptr;
}

Expand Down Expand Up @@ -1208,7 +1209,7 @@ GDALDataset * AAIGDataset::CreateCopy(
else
{
if( pszForceCellsize == nullptr )
CPLError(CE_Warning, CPLE_AppDefined,
ReportError(pszFilename, CE_Warning, CPLE_AppDefined,
"Producing a Golden Surfer style file with DX and DY "
"instead of CELLSIZE since the input pixels are "
"non-square. Use the FORCE_CELLSIZE=TRUE creation "
Expand Down Expand Up @@ -1240,7 +1241,7 @@ GDALDataset * AAIGDataset::CreateCopy(
bool bIgnoreSigDigits = false;
if( pszDecimalPrecision && pszSignificantDigits )
{
CPLError(CE_Warning, CPLE_AppDefined,
ReportError(pszFilename, CE_Warning, CPLE_AppDefined,
"Conflicting precision arguments, using DECIMAL_PRECISION");
bIgnoreSigDigits = true;
}
Expand Down Expand Up @@ -1334,8 +1335,8 @@ GDALDataset * AAIGDataset::CreateCopy(
fpImage) != 1 )
{
eErr = CE_Failure;
CPLError(CE_Failure, CPLE_AppDefined,
"Write failed, disk full?");
ReportError(pszFilename, CE_Failure, CPLE_AppDefined,
"Write failed, disk full?");
break;
}
osBuf = "";
Expand Down Expand Up @@ -1372,8 +1373,8 @@ GDALDataset * AAIGDataset::CreateCopy(
fpImage) != 1 )
{
eErr = CE_Failure;
CPLError(CE_Failure, CPLE_AppDefined,
"Write failed, disk full?");
ReportError(pszFilename, CE_Failure, CPLE_AppDefined,
"Write failed, disk full?");
break;
}
osBuf = "";
Expand All @@ -1388,8 +1389,8 @@ GDALDataset * AAIGDataset::CreateCopy(
pProgressData) )
{
eErr = CE_Failure;
CPLError(CE_Failure, CPLE_UserInterrupt,
"User terminated CreateCopy()");
ReportError(pszFilename, CE_Failure, CPLE_UserInterrupt,
"User terminated CreateCopy()");
}
}

Expand Down Expand Up @@ -1425,8 +1426,9 @@ GDALDataset * AAIGDataset::CreateCopy(
}
else
{
CPLError(CE_Failure, CPLE_FileIO, "Unable to create file %s.",
pszPrjFilename);
ReportError(pszFilename, CE_Failure, CPLE_FileIO,
"Unable to create file %s.",
pszPrjFilename);
}
CPLFree(pszDirname);
CPLFree(pszBasename);
Expand Down
Loading

0 comments on commit f999a23

Please sign in to comment.