[FEATURE] More verbose error logs when using ytdl-sub commands
This commit is contained in:
parent
a48efdc84c
commit
1fac27d216
4 changed files with 30 additions and 2 deletions
|
|
@ -341,6 +341,8 @@ def main() -> List[Tuple[Subscription, FileHandlerTransactionLog]]:
|
||||||
transaction_logs.append(
|
transaction_logs.append(
|
||||||
_view_url_from_cli(config=config, url=args.url, split_chapters=args.split_chapters)
|
_view_url_from_cli(config=config, url=args.url, split_chapters=args.split_chapters)
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
raise ValidationException("Must provide one of the commands: sub, dl, view")
|
||||||
|
|
||||||
if not args.suppress_transaction_log:
|
if not args.suppress_transaction_log:
|
||||||
_output_transaction_log(
|
_output_transaction_log(
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ from typing import Dict
|
||||||
|
|
||||||
from ytdl_sub.config.config_validator import ConfigValidator
|
from ytdl_sub.config.config_validator import ConfigValidator
|
||||||
from ytdl_sub.config.preset import Preset
|
from ytdl_sub.config.preset import Preset
|
||||||
|
from ytdl_sub.utils.exceptions import FileNotFoundException
|
||||||
from ytdl_sub.utils.ffmpeg import FFMPEG
|
from ytdl_sub.utils.ffmpeg import FFMPEG
|
||||||
from ytdl_sub.utils.yaml import load_yaml
|
from ytdl_sub.utils.yaml import load_yaml
|
||||||
from ytdl_sub.validators.file_path_validators import FilePathValidatorMixin
|
from ytdl_sub.validators.file_path_validators import FilePathValidatorMixin
|
||||||
|
|
@ -68,8 +69,20 @@ class ConfigFile(ConfigValidator):
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
Config file validator
|
Config file validator
|
||||||
|
|
||||||
|
Raises
|
||||||
|
------
|
||||||
|
FileNotFoundException
|
||||||
|
Not found
|
||||||
"""
|
"""
|
||||||
config_dict = load_yaml(file_path=config_path)
|
try:
|
||||||
|
config_dict = load_yaml(file_path=config_path)
|
||||||
|
except FileNotFoundException as exc:
|
||||||
|
raise FileNotFoundException(
|
||||||
|
f"The config file '{config_path}' could not be found. "
|
||||||
|
f"Did you set --config correctly?"
|
||||||
|
) from exc
|
||||||
|
|
||||||
return ConfigFile.from_dict(config_dict)
|
return ConfigFile.from_dict(config_dict)
|
||||||
|
|
||||||
def as_dict(self) -> Dict[str, Any]:
|
def as_dict(self) -> Dict[str, Any]:
|
||||||
|
|
|
||||||
|
|
@ -220,7 +220,7 @@ class Logger:
|
||||||
|
|
||||||
# Log validation exceptions as-is
|
# Log validation exceptions as-is
|
||||||
if isinstance(exception, ValidationException):
|
if isinstance(exception, ValidationException):
|
||||||
logger.error(exception)
|
logger.error(str(exception))
|
||||||
# For other uncaught errors, log as bug:
|
# For other uncaught errors, log as bug:
|
||||||
else:
|
else:
|
||||||
logger.exception("An uncaught error occurred:")
|
logger.exception("An uncaught error occurred:")
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import contextlib
|
import contextlib
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
|
@ -80,3 +81,15 @@ def test_args_after_sub_work(mock_sys_exit):
|
||||||
assert mock_sub.call_count == 1
|
assert mock_sub.call_count == 1
|
||||||
assert mock_sub.call_args.kwargs["subscription_paths"] == ["subscriptions.yaml"]
|
assert mock_sub.call_args.kwargs["subscription_paths"] == ["subscriptions.yaml"]
|
||||||
assert Logger._LOGGER_LEVEL == LoggerLevels.VERBOSE
|
assert Logger._LOGGER_LEVEL == LoggerLevels.VERBOSE
|
||||||
|
|
||||||
|
|
||||||
|
def test_no_positional_arg_command(mock_sys_exit):
|
||||||
|
with mock_sys_exit(expected_exit_code=1), patch.object(
|
||||||
|
sys,
|
||||||
|
"argv",
|
||||||
|
["ytdl-sub", "-c", "examples/tv_show_config.yaml", "--log-level", "verbose"],
|
||||||
|
), patch.object(logging.Logger, "error") as mock_error:
|
||||||
|
main()
|
||||||
|
|
||||||
|
assert mock_error.call_count == 1
|
||||||
|
assert mock_error.call_args.args[0] == "Must provide one of the commands: sub, dl, view"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue