Skip to content

Commit

Permalink
Merge pull request #646 from ungarj/fix_fiona_fails
Browse files Browse the repository at this point in the history
adapt to Fiona changing error messages when raising FileNotFoundError
  • Loading branch information
ungarj authored Sep 11, 2024
2 parents 72aaf8c + ae14f8f commit bad4e7d
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions mapchete/io/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,27 @@ def fiona_read(path, mode="r", **kwargs):
logger.debug("reading %s with GDAL options %s", str(path), env.options)
with fiona.open(str(path), mode=mode, **kwargs) as src:
yield src
except DriverError as exc:
except DriverError as fiona_exception:
# look for hints from Fiona that the file does not exist
for i in (
"does not exist in the file system",
"No such file or directory",
"specified key does not exist.",
):
if i in str(repr(exc)):
raise FileNotFoundError(f"path {str(path)} does not exist")
else: # pragma: no cover
raise
if i in str(repr(fiona_exception)): # pragma: no cover
break
# if there are no hints, investigate further
else:
# if file exists or exists check fails, raise original Fiona exception
try:
exists = path.exists()
except Exception: # pragma: no cover
raise fiona_exception
if exists:
raise fiona_exception

# file does not exist
raise FileNotFoundError(f"path {str(path)} does not exist")


@contextmanager
Expand Down

6 comments on commit bad4e7d

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Coverage

missing coverage
FileStmtsMissCoverMissing
__init__.py300100% 
enums.py310100% 
errors.py170100% 
index.py1790100% 
log.py500100% 
path.py3820100% 
pretty.py160100% 
protocols.py140100% 
registered.py50100% 
settings.py320100% 
stac.py1470100% 
testing.py980100% 
tile.py1580100% 
timer.py370100% 
types.py2160100% 
validate.py630100% 
cli
   __init__.py00100% 
   main.py90100% 
   mpath.py830100% 
   options.py1270100% 
   progress_bar.py370100% 
cli/default
   __init__.py00100% 
   convert.py630100% 
   cp.py330100% 
   create.py360100% 
   execute.py420100% 
   formats.py190100% 
   index.py420100% 
   processes.py180100% 
   rm.py250100% 
   serve.py690100% 
   stac.py600100% 
commands
   __init__.py60100% 
   convert.py780100% 
   cp.py650100% 
   execute.py700100% 
   index.py340100% 
   observer.py90100% 
   parser.py890100% 
   rm.py440100% 
config
   __init__.py40100% 
   base.py3550100% 
   models.py1770100% 
   parse.py770100% 
   process_func.py890100% 
executor
   __init__.py170100% 
   base.py770100% 
   concurrent_futures.py700100% 
   dask.py1050100% 
   future.py820100% 
   sequential.py330100% 
   types.py130100% 
formats
   __init__.py30100% 
   base.py1740100% 
   drivers.py00100% 
   loaders.py430100% 
   protocols.py130100% 
   tools.py1530100% 
formats/default
   __init__.py00100% 
   _fiona_base.py510100% 
   flatgeobuf.py140100% 
   geojson.py120100% 
   gtiff.py1950100% 
   mapchete_input.py160100% 
   png.py660100% 
   png_hillshade.py560100% 
   raster_file.py850100% 
   tile_directory.py1010100% 
   vector_file.py750100% 
geometry
   __init__.py100100% 
   filter.py280100% 
   footprints.py390100% 
   latlon.py300100% 
   repair.py80100% 
   reproject.py690100% 
   segmentize.py230100% 
   shape.py90100% 
   transform.py280100% 
   types.py270100% 
io
   __init__.py70100% 
   _json.py60100% 
   _misc.py780100% 
   _path.py00100% 
   profiles.py60100% 
   vector.py2900100% 
io/raster
   __init__.py80100% 
   array.py1040100% 
   convert.py230100% 
   mosaic.py1020100% 
   open.py140100% 
   read.py1670100% 
   referenced_raster.py950100% 
   write.py1000100% 
processes
   __init__.py170100% 
   clip.py170100% 
   contours.py520100% 
   convert.py380100% 
   hillshade.py490100% 
processes/examples
   __init__.py00100% 
   example_process.py60100% 
processing
   __init__.py30100% 
   base.py2620100% 
   execute.py710100% 
   mp.py260100% 
   tasks.py2890100% 
   types.py450100% 
processing/profilers
   __init__.py50100% 
   memory.py600100% 
   requests.py250100% 
   time.py220100% 
static
   __init__.py00100% 
   process_template.py10100% 
TOTAL69480100% 

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Coverage

missing coverage
FileStmtsMissCoverMissing
__init__.py300100% 
enums.py310100% 
errors.py170100% 
index.py1790100% 
log.py500100% 
path.py3820100% 
pretty.py160100% 
protocols.py140100% 
registered.py50100% 
settings.py320100% 
stac.py1470100% 
testing.py980100% 
tile.py1580100% 
timer.py370100% 
types.py2160100% 
validate.py630100% 
cli
   __init__.py00100% 
   main.py90100% 
   mpath.py830100% 
   options.py1270100% 
   progress_bar.py370100% 
cli/default
   __init__.py00100% 
   convert.py630100% 
   cp.py330100% 
   create.py360100% 
   execute.py420100% 
   formats.py190100% 
   index.py420100% 
   processes.py180100% 
   rm.py250100% 
   serve.py690100% 
   stac.py600100% 
commands
   __init__.py60100% 
   convert.py780100% 
   cp.py650100% 
   execute.py700100% 
   index.py340100% 
   observer.py90100% 
   parser.py890100% 
   rm.py440100% 
config
   __init__.py40100% 
   base.py3550100% 
   models.py1770100% 
   parse.py770100% 
   process_func.py890100% 
executor
   __init__.py170100% 
   base.py770100% 
   concurrent_futures.py700100% 
   dask.py1050100% 
   future.py820100% 
   sequential.py330100% 
   types.py130100% 
formats
   __init__.py30100% 
   base.py1740100% 
   drivers.py00100% 
   loaders.py430100% 
   protocols.py130100% 
   tools.py1530100% 
formats/default
   __init__.py00100% 
   _fiona_base.py510100% 
   flatgeobuf.py140100% 
   geojson.py120100% 
   gtiff.py1950100% 
   mapchete_input.py160100% 
   png.py660100% 
   png_hillshade.py560100% 
   raster_file.py850100% 
   tile_directory.py1010100% 
   vector_file.py750100% 
geometry
   __init__.py100100% 
   filter.py280100% 
   footprints.py390100% 
   latlon.py300100% 
   repair.py80100% 
   reproject.py690100% 
   segmentize.py230100% 
   shape.py90100% 
   transform.py280100% 
   types.py270100% 
io
   __init__.py70100% 
   _json.py60100% 
   _misc.py780100% 
   _path.py00100% 
   profiles.py60100% 
   vector.py2900100% 
io/raster
   __init__.py80100% 
   array.py1040100% 
   convert.py230100% 
   mosaic.py1020100% 
   open.py140100% 
   read.py1670100% 
   referenced_raster.py950100% 
   write.py1000100% 
processes
   __init__.py170100% 
   clip.py170100% 
   contours.py520100% 
   convert.py380100% 
   hillshade.py490100% 
processes/examples
   __init__.py00100% 
   example_process.py60100% 
processing
   __init__.py30100% 
   base.py2620100% 
   execute.py710100% 
   mp.py260100% 
   tasks.py2890100% 
   types.py450100% 
processing/profilers
   __init__.py50100% 
   memory.py600100% 
   requests.py250100% 
   time.py220100% 
static
   __init__.py00100% 
   process_template.py10100% 
TOTAL69480100% 

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Coverage

missing coverage
FileStmtsMissCoverMissing
__init__.py300100% 
enums.py310100% 
errors.py170100% 
index.py1790100% 
log.py500100% 
path.py3820100% 
pretty.py160100% 
protocols.py140100% 
registered.py50100% 
settings.py320100% 
stac.py1470100% 
testing.py980100% 
tile.py1580100% 
timer.py370100% 
types.py2160100% 
validate.py630100% 
cli
   __init__.py00100% 
   main.py90100% 
   mpath.py830100% 
   options.py1270100% 
   progress_bar.py370100% 
cli/default
   __init__.py00100% 
   convert.py630100% 
   cp.py330100% 
   create.py360100% 
   execute.py420100% 
   formats.py190100% 
   index.py420100% 
   processes.py180100% 
   rm.py250100% 
   serve.py690100% 
   stac.py600100% 
commands
   __init__.py60100% 
   convert.py780100% 
   cp.py650100% 
   execute.py700100% 
   index.py340100% 
   observer.py90100% 
   parser.py890100% 
   rm.py440100% 
config
   __init__.py40100% 
   base.py3550100% 
   models.py1770100% 
   parse.py770100% 
   process_func.py890100% 
executor
   __init__.py170100% 
   base.py770100% 
   concurrent_futures.py700100% 
   dask.py1050100% 
   future.py820100% 
   sequential.py330100% 
   types.py130100% 
formats
   __init__.py30100% 
   base.py1740100% 
   drivers.py00100% 
   loaders.py430100% 
   protocols.py130100% 
   tools.py1530100% 
formats/default
   __init__.py00100% 
   _fiona_base.py510100% 
   flatgeobuf.py140100% 
   geojson.py120100% 
   gtiff.py1950100% 
   mapchete_input.py160100% 
   png.py660100% 
   png_hillshade.py560100% 
   raster_file.py850100% 
   tile_directory.py1010100% 
   vector_file.py750100% 
geometry
   __init__.py100100% 
   filter.py280100% 
   footprints.py390100% 
   latlon.py300100% 
   repair.py80100% 
   reproject.py690100% 
   segmentize.py230100% 
   shape.py90100% 
   transform.py280100% 
   types.py270100% 
io
   __init__.py70100% 
   _json.py60100% 
   _misc.py780100% 
   _path.py00100% 
   profiles.py60100% 
   vector.py2900100% 
io/raster
   __init__.py80100% 
   array.py1040100% 
   convert.py230100% 
   mosaic.py1020100% 
   open.py140100% 
   read.py1670100% 
   referenced_raster.py950100% 
   write.py1000100% 
processes
   __init__.py170100% 
   clip.py170100% 
   contours.py520100% 
   convert.py380100% 
   hillshade.py490100% 
processes/examples
   __init__.py00100% 
   example_process.py60100% 
processing
   __init__.py30100% 
   base.py2620100% 
   execute.py710100% 
   mp.py260100% 
   tasks.py2890100% 
   types.py450100% 
processing/profilers
   __init__.py50100% 
   memory.py600100% 
   requests.py250100% 
   time.py220100% 
static
   __init__.py00100% 
   process_template.py10100% 
TOTAL69480100% 

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Coverage

missing coverage
FileStmtsMissCoverMissing
__init__.py300100% 
enums.py310100% 
errors.py170100% 
index.py1790100% 
log.py500100% 
path.py3820100% 
pretty.py160100% 
protocols.py140100% 
registered.py50100% 
settings.py320100% 
stac.py1470100% 
testing.py980100% 
tile.py1580100% 
timer.py370100% 
types.py2160100% 
validate.py630100% 
cli
   __init__.py00100% 
   main.py90100% 
   mpath.py830100% 
   options.py1270100% 
   progress_bar.py370100% 
cli/default
   __init__.py00100% 
   convert.py630100% 
   cp.py330100% 
   create.py360100% 
   execute.py420100% 
   formats.py190100% 
   index.py420100% 
   processes.py180100% 
   rm.py250100% 
   serve.py690100% 
   stac.py600100% 
commands
   __init__.py60100% 
   convert.py780100% 
   cp.py650100% 
   execute.py700100% 
   index.py340100% 
   observer.py90100% 
   parser.py890100% 
   rm.py440100% 
config
   __init__.py40100% 
   base.py3550100% 
   models.py1770100% 
   parse.py770100% 
   process_func.py890100% 
executor
   __init__.py170100% 
   base.py770100% 
   concurrent_futures.py700100% 
   dask.py1050100% 
   future.py820100% 
   sequential.py330100% 
   types.py130100% 
formats
   __init__.py30100% 
   base.py1740100% 
   drivers.py00100% 
   loaders.py430100% 
   protocols.py130100% 
   tools.py1530100% 
formats/default
   __init__.py00100% 
   _fiona_base.py510100% 
   flatgeobuf.py140100% 
   geojson.py120100% 
   gtiff.py1950100% 
   mapchete_input.py160100% 
   png.py660100% 
   png_hillshade.py560100% 
   raster_file.py850100% 
   tile_directory.py1010100% 
   vector_file.py750100% 
geometry
   __init__.py100100% 
   filter.py280100% 
   footprints.py390100% 
   latlon.py300100% 
   repair.py80100% 
   reproject.py690100% 
   segmentize.py230100% 
   shape.py90100% 
   transform.py280100% 
   types.py270100% 
io
   __init__.py70100% 
   _json.py60100% 
   _misc.py780100% 
   _path.py00100% 
   profiles.py60100% 
   vector.py2900100% 
io/raster
   __init__.py80100% 
   array.py1040100% 
   convert.py230100% 
   mosaic.py1020100% 
   open.py140100% 
   read.py1670100% 
   referenced_raster.py950100% 
   write.py1000100% 
processes
   __init__.py170100% 
   clip.py170100% 
   contours.py520100% 
   convert.py380100% 
   hillshade.py490100% 
processes/examples
   __init__.py00100% 
   example_process.py60100% 
processing
   __init__.py30100% 
   base.py2620100% 
   execute.py710100% 
   mp.py260100% 
   tasks.py2890100% 
   types.py450100% 
processing/profilers
   __init__.py50100% 
   memory.py600100% 
   requests.py250100% 
   time.py220100% 
static
   __init__.py00100% 
   process_template.py10100% 
TOTAL69480100% 

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Coverage

missing coverage
FileStmtsMissCoverMissing
__init__.py300100% 
enums.py310100% 
errors.py170100% 
index.py1790100% 
log.py500100% 
path.py3820100% 
pretty.py160100% 
protocols.py140100% 
registered.py50100% 
settings.py320100% 
stac.py1470100% 
testing.py980100% 
tile.py1580100% 
timer.py370100% 
types.py2160100% 
validate.py630100% 
cli
   __init__.py00100% 
   main.py90100% 
   mpath.py830100% 
   options.py1270100% 
   progress_bar.py370100% 
cli/default
   __init__.py00100% 
   convert.py630100% 
   cp.py330100% 
   create.py360100% 
   execute.py420100% 
   formats.py190100% 
   index.py420100% 
   processes.py180100% 
   rm.py250100% 
   serve.py690100% 
   stac.py600100% 
commands
   __init__.py60100% 
   convert.py780100% 
   cp.py650100% 
   execute.py700100% 
   index.py340100% 
   observer.py90100% 
   parser.py890100% 
   rm.py440100% 
config
   __init__.py40100% 
   base.py3550100% 
   models.py1770100% 
   parse.py770100% 
   process_func.py890100% 
executor
   __init__.py170100% 
   base.py770100% 
   concurrent_futures.py700100% 
   dask.py1050100% 
   future.py820100% 
   sequential.py330100% 
   types.py130100% 
formats
   __init__.py30100% 
   base.py1740100% 
   drivers.py00100% 
   loaders.py430100% 
   protocols.py130100% 
   tools.py1530100% 
formats/default
   __init__.py00100% 
   _fiona_base.py510100% 
   flatgeobuf.py140100% 
   geojson.py120100% 
   gtiff.py1950100% 
   mapchete_input.py160100% 
   png.py660100% 
   png_hillshade.py560100% 
   raster_file.py850100% 
   tile_directory.py1010100% 
   vector_file.py750100% 
geometry
   __init__.py100100% 
   filter.py280100% 
   footprints.py390100% 
   latlon.py300100% 
   repair.py80100% 
   reproject.py690100% 
   segmentize.py230100% 
   shape.py90100% 
   transform.py280100% 
   types.py270100% 
io
   __init__.py70100% 
   _json.py60100% 
   _misc.py780100% 
   _path.py00100% 
   profiles.py60100% 
   vector.py2900100% 
io/raster
   __init__.py80100% 
   array.py1040100% 
   convert.py230100% 
   mosaic.py1020100% 
   open.py140100% 
   read.py1670100% 
   referenced_raster.py950100% 
   write.py1000100% 
processes
   __init__.py170100% 
   clip.py170100% 
   contours.py520100% 
   convert.py380100% 
   hillshade.py490100% 
processes/examples
   __init__.py00100% 
   example_process.py60100% 
processing
   __init__.py30100% 
   base.py2620100% 
   execute.py710100% 
   mp.py260100% 
   tasks.py2890100% 
   types.py450100% 
processing/profilers
   __init__.py50100% 
   memory.py600100% 
   requests.py250100% 
   time.py220100% 
static
   __init__.py00100% 
   process_template.py10100% 
TOTAL69480100% 

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Coverage

missing coverage
FileStmtsMissCoverMissing
__init__.py300100% 
enums.py310100% 
errors.py170100% 
index.py1790100% 
log.py500100% 
path.py3820100% 
pretty.py160100% 
protocols.py140100% 
registered.py50100% 
settings.py320100% 
stac.py1470100% 
testing.py980100% 
tile.py1580100% 
timer.py370100% 
types.py2160100% 
validate.py630100% 
cli
   __init__.py00100% 
   main.py90100% 
   mpath.py830100% 
   options.py1270100% 
   progress_bar.py370100% 
cli/default
   __init__.py00100% 
   convert.py630100% 
   cp.py330100% 
   create.py360100% 
   execute.py420100% 
   formats.py190100% 
   index.py420100% 
   processes.py180100% 
   rm.py250100% 
   serve.py690100% 
   stac.py600100% 
commands
   __init__.py60100% 
   convert.py780100% 
   cp.py650100% 
   execute.py700100% 
   index.py340100% 
   observer.py90100% 
   parser.py890100% 
   rm.py440100% 
config
   __init__.py40100% 
   base.py3550100% 
   models.py1770100% 
   parse.py770100% 
   process_func.py890100% 
executor
   __init__.py170100% 
   base.py770100% 
   concurrent_futures.py700100% 
   dask.py1050100% 
   future.py820100% 
   sequential.py330100% 
   types.py130100% 
formats
   __init__.py30100% 
   base.py1740100% 
   drivers.py00100% 
   loaders.py430100% 
   protocols.py130100% 
   tools.py1530100% 
formats/default
   __init__.py00100% 
   _fiona_base.py510100% 
   flatgeobuf.py140100% 
   geojson.py120100% 
   gtiff.py1950100% 
   mapchete_input.py160100% 
   png.py660100% 
   png_hillshade.py560100% 
   raster_file.py850100% 
   tile_directory.py1010100% 
   vector_file.py750100% 
geometry
   __init__.py100100% 
   filter.py280100% 
   footprints.py390100% 
   latlon.py300100% 
   repair.py80100% 
   reproject.py690100% 
   segmentize.py230100% 
   shape.py90100% 
   transform.py280100% 
   types.py270100% 
io
   __init__.py70100% 
   _json.py60100% 
   _misc.py780100% 
   _path.py00100% 
   profiles.py60100% 
   vector.py2900100% 
io/raster
   __init__.py80100% 
   array.py1040100% 
   convert.py230100% 
   mosaic.py1020100% 
   open.py140100% 
   read.py1670100% 
   referenced_raster.py950100% 
   write.py1000100% 
processes
   __init__.py170100% 
   clip.py170100% 
   contours.py520100% 
   convert.py380100% 
   hillshade.py490100% 
processes/examples
   __init__.py00100% 
   example_process.py60100% 
processing
   __init__.py30100% 
   base.py2620100% 
   execute.py710100% 
   mp.py260100% 
   tasks.py2890100% 
   types.py450100% 
processing/profilers
   __init__.py50100% 
   memory.py600100% 
   requests.py250100% 
   time.py220100% 
static
   __init__.py00100% 
   process_template.py10100% 
TOTAL69480100% 

Please sign in to comment.