Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
add invalid YAML config error handle
NTFSvolume717931064251
diff --git a/cyberdrop_dl/clients/errors.py b/cyberdrop_dl/clients/errors.pyindex 73c4ece1b..57e76e512 100644--- a/cyberdrop_dl/clients/errors.py+++ b/cyberdrop_dl/clients/errors.py@@ -1,4 +1,6 @@from typing import TYPE_CHECKING+from pathlib import Path+from yaml.constructor import ConstructorErrorif TYPE_CHECKING:from cyberdrop_dl.scraper.crawler import ScrapeItem@@ -10,6 +12,16 @@ class InvalidContentTypeFailure(Exception):self.message = messagesuper().__init__(self.message)+class InvalidYamlConfig(Exception):+ """This error will be thrown when a yaml config file has invalid values"""++ def __init__(self, file: Path, e: ConstructorError):+ self.file = file+ mark = e.problem_mark if hasattr(e, 'problem_mark') else e+ self.message = f"ERROR: File '{file}' has an invalid config. Please verify and edit it manually\n {mark}"+ self.message_rich = self.message.replace("ERROR:", "[bold red]ERROR:[/bold red]")+ super().__init__(self.message)+class NoExtensionFailure(Exception):"""This error will be thrown when no extension is given for a file"""diff --git a/cyberdrop_dl/main.py b/cyberdrop_dl/main.pyindex 9abb5c678..03dd4362e 100644--- a/cyberdrop_dl/main.py+++ b/cyberdrop_dl/main.py@@ -12,7 +12,7 @@ from cyberdrop_dl.ui.ui import program_uifrom cyberdrop_dl.utils.sorting import Sorterfrom cyberdrop_dl.utils.utilities import check_latest_pypi, log_with_color, check_partials_and_empty_folders, logfrom cyberdrop_dl.managers.console_manager import print_-+from cyberdrop_dl.clients.errors import InvalidYamlConfigdef startup() -> Manager:"""@@ -30,6 +30,10 @@ def startup() -> Manager:return manager+ except InvalidYamlConfig as e:+ print_ (e.message_rich)+ exit (1)+except KeyboardInterrupt:print_("\nExiting...")exit(0)@@ -177,6 +181,7 @@ def main():with contextlib.suppress(RuntimeError):try:asyncio.run(director(manager))+except KeyboardInterrupt:print_("\nTrying to Exit...")with contextlib.suppress(Exception):diff --git a/cyberdrop_dl/managers/config_manager.py b/cyberdrop_dl/managers/config_manager.pyindex 303ab7480..314a153bd 100644--- a/cyberdrop_dl/managers/config_manager.py+++ b/cyberdrop_dl/managers/config_manager.py@@ -9,6 +9,7 @@ import yamlfrom cyberdrop_dl.managers.log_manager import LogManagerfrom cyberdrop_dl.utils.args.config_definitions import authentication_settings, settings, global_settings+from cyberdrop_dl.clients.errors import InvalidYamlConfigif TYPE_CHECKING:from cyberdrop_dl.managers.manager import Manager@@ -32,9 +33,12 @@ def _save_yaml(file: Path, data: Dict) -> None:def _load_yaml(file: Path) -> Dict:"""Loads a yaml file and returns it as a dict"""- with open(file, 'r') as yaml_file:- yaml_values = yaml.load(yaml_file.read(), Loader=yaml.FullLoader)- return yaml_values if yaml_values else {}+ try:+ with open(file, 'r') as yaml_file:+ yaml_values = yaml.load(yaml_file.read(), Loader=yaml.FullLoader)+ return yaml_values if yaml_values else {}+ except yaml.constructor.ConstructorError as e:+ raise InvalidYamlConfig(file, e)def get_keys(dl, keys=None) -> set: