[gdal-dev] OGR error handling

Ari Jolma ari.jolma at gmail.com
Wed Oct 21 00:13:27 PDT 2015



On 20.10.2015 22:20, Andre Vautour wrote:
> Hi all,
>
> We are using OGRSFDriver::CopyDataSource() to copy a GML data source 
> to a memory data source on v1.11.x.
>
> We have encountered a problem where one of the feature tags of a 
> particular GML file we are trying to read is malformed. What we are 
> seeing is that an error occurs in OGRGMLLayer::GetNextFeature(), which 
> gets reported as expected via CPLError().
>
> The problem we are faced with is that that error seems to be reset 
> using CPLErrorReset() before control returns to the caller of 
> CopyDataSource(), specifically in OGRDataSource::CopyLayer(). The 
> result is that the copying silently skips over problematic features.
>
>
> Is that the expected behavior of copying a data source? Given that 
> GDAL isn't necessarily exception safe, we've typically used 
> CPLGetLastErrorNo after control returns to get at such errors that 
> occur in functions that do not return an error directly in the method 
> signature. Is there a better approach to error handling that we 
> could/should be using?

If CPLError gets called then the issue is reported and it is not 
silently skipped. I believe the driver writer has judged the issue not 
an error but only worth of a warning, thus the GetNextFeature does not 
return a NULL, which would lead to immediate return without error reset.

As Even wrote I guess you should make your code to keep an eye on 
warnings and not accept the copy if there are any you deem too serious.

Ari

>
> Thanks,
> André
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev



More information about the gdal-dev mailing list