Skip to content

Commit

Permalink
fs: add generic implementation of log_exceptions for transfer/copy
Browse files Browse the repository at this point in the history
  • Loading branch information
pmrowla committed Oct 18, 2022
1 parent 929ecec commit de32232
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/dvc_objects/fs/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import logging
import os
from contextlib import suppress
from typing import TYPE_CHECKING, List, Optional
from functools import wraps
from typing import TYPE_CHECKING, Any, Callable, List, Optional

from .callbacks import DEFAULT_CALLBACK
from .local import LocalFileSystem, localfs
Expand All @@ -15,6 +16,31 @@
logger = logging.getLogger(__name__)


def log_exceptions(func: Callable) -> Callable:
@wraps(func)
def wrapper(
from_fs: "FileSystem",
from_path: "AnyFSPath",
to_fs: "FileSystem",
to_path: "AnyFSPath",
*args: Any,
**kwargs: Any,
) -> int:
try:
func(from_fs, from_path, to_fs, to_path, *args, **kwargs)
return 0
except Exception as exc: # pylint: disable=broad-except
# NOTE: this means we ran out of file descriptors and there is no
# reason to try to proceed, as we will hit this error anyways.
# pylint: disable=no-member
if isinstance(exc, OSError) and exc.errno == errno.EMFILE:
raise
logger.exception("failed to transfer '%s'", from_path)
return 1

return wrapper


def _link(
link: "str",
from_fs: "FileSystem",
Expand Down

0 comments on commit de32232

Please sign in to comment.