Skip to content

Commit

Permalink
refactor: do not request logs from cookie extraction errors
Browse files Browse the repository at this point in the history
  • Loading branch information
NTFSvolume committed Jan 31, 2025
1 parent dee8c51 commit 638cc64
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
10 changes: 8 additions & 2 deletions cyberdrop_dl/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from time import perf_counter
from typing import TYPE_CHECKING

import browser_cookie3
from pydantic import ValidationError
from rich.console import Console
from rich.logging import RichHandler
Expand Down Expand Up @@ -66,6 +67,10 @@ def startup() -> Manager | None:
startup_logger.info("Exiting...")
sys.exit(0)

except browser_cookie3.BrowserCookieError:
startup_logger.exception("")
sys.exit(1)

except Exception:
msg = "An error occurred, please report this to the developer with your logs file:"
startup_logger.exception(msg)
Expand Down Expand Up @@ -199,8 +204,9 @@ async def wrapper(*args, **kwargs):
exceptions = [e]
if isinstance(e, ExceptionGroup):
exceptions = e.exceptions
msg = "An error occurred, please report this to the developer with your logs file:"
log_with_color(msg, "bold red", 50, show_in_stats=False)
if not isinstance(exceptions[0], browser_cookie3.BrowserCookieError):
msg = "An error occurred, please report this to the developer with your logs file:"
log_with_color(msg, "bold red", 50, show_in_stats=False)
for exc in exceptions:
log_with_color(f" {exc}", "bold red", 50, show_in_stats=False, exc_info=exc)

Expand Down
15 changes: 6 additions & 9 deletions cyberdrop_dl/utils/cookie_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,19 @@ def wrapper(*args, **kwargs) -> None:
try:
return func(*args, **kwargs)
except PermissionError:
msg = """
We've encountered a Permissions Error. Please close all browsers and try again
If you are still having issues, make sure all browsers processes are closed in Task Manager
"""
msg = """We've encountered a Permissions Error. Please close all browsers and try again
If you are still having issues, make sure all browsers processes are closed in Task Manager"""
msg = dedent(msg)

except ValueError as e:
msg = str(e)

except UnsupportedBrowserError as e:
msg = f"\nERROR: {e!s}"
msg = f"ERROR: {e!s}"

except browser_cookie3.BrowserCookieError as e:
msg = """
Browser extraction ran into an error, the selected browser(s) may not be available on your system
If you are still having issues, make sure all browsers processes are closed in Task Manager.
"""
msg = """Browser extraction ran into an error, the selected browser(s) may not be available on your system
If you are still having issues, make sure all browsers processes are closed in Task Manager."""

msg = dedent(msg) + f"\nERROR: {e!s}"

Expand All @@ -72,6 +68,7 @@ def get_cookies_from_browsers(
raise ValueError(msg)

browsers = browsers or manager.config_manager.settings_data.browser_cookies.browsers
browsers = list(map(str.lower, browsers))
domains: list[str] = domains or manager.config_manager.settings_data.browser_cookies.sites
extractors = [(str(b), getattr(browser_cookie3, b)) for b in browsers if hasattr(browser_cookie3, b)]

Expand Down

0 comments on commit 638cc64

Please sign in to comment.