Skip to content

Commit

Permalink
account for potential exceptions during exists check
Browse files Browse the repository at this point in the history
  • Loading branch information
ungarj committed Sep 11, 2024
1 parent 8e1199c commit dee3d24
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions mapchete/io/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +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")
if i in str(repr(fiona_exception)): # pragma: no cover
break
# if there are no hints, investigate further
else:
if not path.exists():
raise FileNotFoundError(f"path {str(path)} does not exist")
raise
# 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

0 comments on commit dee3d24

Please sign in to comment.