Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adapt to Fiona changing error messages when raising FileNotFoundError #646

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading