Skip to content

Bulk asynchronous downloader for multiple file hosts

refactor: handle early Keyboard interrupts

NTFSvolumebb2118e3dd5e
diff --git a/cyberdrop_dl/__main__.py b/cyberdrop_dl/__main__.py
index 63c45c5e3..5efbdf469 100644
--- a/cyberdrop_dl/__main__.py
+++ b/cyberdrop_dl/__main__.py
@@ -1,20 +1,13 @@
from __future__ import annotations
-import sys
from typing import TYPE_CHECKING
-from cyberdrop_dl import tracebacks
-from cyberdrop_dl.cli import app
-from cyberdrop_dl.exceptions import CDLConfigRuntimeErrorsGroup, DatabaseError
-
if TYPE_CHECKING:
from collections.abc import Sequence
from rich.console import RenderableType
from rich.panel import Panel
-tracebacks.install_exception_hook()
-
def _error_panel(message: RenderableType, title: str = "Error") -> Panel:
# Based on the default cyclopts panel
@@ -32,18 +25,24 @@ def _error_panel(message: RenderableType, title: str = "Error") -> Panel:
def run_cdl(args: Sequence[str] | None = None) -> int:
- from pydantic import ValidationError
-
+ from cyberdrop_dl import tracebacks
from cyberdrop_dl.logs import setup_console_logging
+ tracebacks.install_exception_hook()
+
with setup_console_logging():
+ from pydantic import ValidationError
+
+ from cyberdrop_dl.cli import app
+ from cyberdrop_dl.exceptions import CDLConfigRuntimeErrorsGroup, DatabaseError
+
try:
app(args)
except (ValidationError, DatabaseError) as exc:
- tb = tracebacks.from_exception(exc.with_traceback(None), chain_traceback=False)
+ tb = tracebacks.from_exception(exc.with_traceback(None))
app.console.print(_error_panel(tb))
except CDLConfigRuntimeErrorsGroup as exc_group:
- tb = tracebacks.from_exception(exc_group, chain_traceback=False)
+ tb = tracebacks.from_exception(exc_group)
app.console.print(_error_panel(tb, title=exc_group.message or "Invalid Config"))
else:
return 0
@@ -52,7 +51,12 @@ def run_cdl(args: Sequence[str] | None = None) -> int:
def main(args: Sequence[str] | None = None) -> None:
- sys.exit(run_cdl(args))
+ try:
+ raise SystemExit(run_cdl(args))
+ except KeyboardInterrupt:
+ import logging
+
+ logging.getLogger("cyberdrop_dl").info("Exiting (Ctrl + C) ...")
if __name__ == "__main__":
diff --git a/cyberdrop_dl/tracebacks.py b/cyberdrop_dl/tracebacks.py
index e24b7ce97..cc51a53d5 100644
--- a/cyberdrop_dl/tracebacks.py
+++ b/cyberdrop_dl/tracebacks.py
@@ -61,7 +61,7 @@ def install_exception_hook(*, show_locals: bool = False) -> None:
)
-def from_exception(exc: Exception, *, chain_traceback: bool = True) -> Traceback:
+def from_exception(exc: Exception, *, chain_traceback: bool = False) -> Traceback:
from rich.traceback import Traceback
return Traceback.from_exception(type(exc), exc, None if not chain_traceback else exc.__traceback__)