Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
refactor: nicely handle exceptions from inner taskgroups (#1899)
NTFSvolume7566ad9d9182
diff --git a/cyberdrop_dl/utils/__init__.py b/cyberdrop_dl/utils/__init__.pyindex 3df09f1ee..bac9688da 100644--- a/cyberdrop_dl/utils/__init__.py+++ b/cyberdrop_dl/utils/__init__.py@@ -50,6 +50,22 @@ _R = TypeVar("_R")logger = logging.getLogger(__name__)+def group_exceptions(message: str | None = None) -> Generator[None]:+ try:+ yield+ except ExceptionGroup as e:+ raise ExceptionGroup(message or _exc_group_msg(e), e.exceptions) from None+++def _exc_group_msg(e: ExceptionGroup) -> str:+ if "unhandled errors in a TaskGroup" not in e.message:+ return e.message++ first = e.exceptions[0]+ return getattr(first, "ui_failure", None) or str(first)++@contextlib.contextmanagerdef error_handling_context(self: _HasManager, item: ScrapeItem | MediaItem | yarl.URL) -> Generator[None]: # noqa: C901, PLR0912link: yarl.URL = item if isinstance(item, yarl.URL) else item.url@@ -57,9 +73,13 @@ def error_handling_context(self: _HasManager, item: ScrapeItem | MediaItem | yarlink_to_show: yarl.URL | str = ""is_segment: bool = getattr(item, "is_segment", False)try:- yield+ with group_exceptions():+ yieldexcept TooManyCrawlerErrors:return+ except ExceptionGroup as e:+ error_log_msg = ErrorLogMessage(_exc_group_msg(e), str(e))+ exc_info = e.with_traceback(None)except CDLBaseError as e:error_log_msg = ErrorLogMessage(e.ui_failure, str(e))origin = e.origin