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

fix masking of ClientResponseError where some tool raises a generic E… #661

Merged
merged 3 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions mapchete/executor/future.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def skip(skip_info: Optional[Any] = None, result: Optional[Any] = None) -> MFutu
def from_func(
func: Callable, fargs: Optional[Tuple] = None, fkwargs: Optional[Dict] = None
) -> MFuture:
fkwargs = fkwargs or {}
try:
return MFuture(result=func(*fargs, **fkwargs))
except Exception as exc: # pragma: no cover
Expand Down
32 changes: 21 additions & 11 deletions mapchete/io/_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,24 @@ def copy(src_path, dst_path, src_fs=None, dst_fs=None, overwrite=False):
# create parent directories on local filesystems
dst_path.parent.makedirs()

# copy either within a filesystem or between filesystems
if src_path.fs == dst_path.fs:
src_path.fs.copy(str(src_path), str(dst_path))
else:
# read source data first
with src_path.open("rb") as src:
content = src.read()
# only write to destination if reading source data didn't raise errors,
# otherwise we can end up with empty objects on an object store
with dst_path.open("wb") as dst:
dst.write(content)
try:
# copy either within a filesystem or between filesystems
if src_path.fs == dst_path.fs:
src_path.fs.copy(str(src_path), str(dst_path))
else:
# read source data first
with src_path.open("rb") as src:
content = src.read()
# only write to destination if reading source data didn't raise errors,
# otherwise we can end up with empty objects on an object store
with dst_path.open("wb") as dst:
dst.write(content)
except Exception as exception: # pragma: no cover
# This is a hack because some tool using aiohttp does not raise a
# ClientResponseError directly but masks it as a generic Exception and thus
# preventing our retry mechanism to kick in.
if repr(exception).startswith('Exception("ClientResponseError'):
raise ConnectionError(repr(exception)).with_traceback(
exception.__traceback__
) from exception
raise
Loading