[BACKEND] More explicit error message for PermissionError (#736)
Do not print the full stack trace when a PermissionError occurs
This commit is contained in:
parent
3c87dc9f8e
commit
3d9c35519d
2 changed files with 22 additions and 0 deletions
|
|
@ -221,6 +221,13 @@ class Logger:
|
|||
# Log validation exceptions as-is
|
||||
if isinstance(exception, ValidationException):
|
||||
logger.error(str(exception))
|
||||
# Log permission errors explicitly
|
||||
elif isinstance(exception, PermissionError):
|
||||
logger.error(
|
||||
"A permission error occurred:\n%s\n"
|
||||
"The user running ytdl-sub must have permission to this file/directory.",
|
||||
str(exception),
|
||||
)
|
||||
# For other uncaught errors, log as bug:
|
||||
else:
|
||||
logger.exception("An uncaught error occurred:")
|
||||
|
|
|
|||
|
|
@ -69,6 +69,21 @@ def test_main_uncaught_error(capsys, mock_sys_exit, expected_uncaught_error_mess
|
|||
assert mock_error.call_args.args[2] == Logger.debug_log_filename()
|
||||
|
||||
|
||||
def test_main_permission_error(capsys, mock_sys_exit, expected_uncaught_error_message):
|
||||
permission_error = PermissionError("test")
|
||||
with mock_sys_exit(expected_exit_code=1), patch(
|
||||
"src.ytdl_sub.main._main", side_effect=permission_error
|
||||
), patch.object(logging.Logger, "error") as mock_error:
|
||||
main()
|
||||
|
||||
assert mock_error.call_count == 1
|
||||
assert mock_error.call_args.args[0] == (
|
||||
"A permission error occurred:\n%s\n"
|
||||
"The user running ytdl-sub must have permission to this file/directory."
|
||||
)
|
||||
assert mock_error.call_args.args[1] == "test"
|
||||
|
||||
|
||||
def test_args_after_sub_work(mock_sys_exit):
|
||||
with mock_sys_exit(expected_exit_code=0), patch.object(
|
||||
sys,
|
||||
|
|
|
|||
Loading…
Reference in a new issue