From c687dafdd2b373565e3733965a00ee1085d1c9b3 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Fri, 6 Oct 2023 21:00:23 -0700 Subject: [PATCH] Fix a traceback when an invalid command-line flag or action is used (#768). --- NEWS | 3 ++- borgmatic/logger.py | 4 ++-- tests/end-to-end/test_invalid_flag.py | 11 +++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 tests/end-to-end/test_invalid_flag.py diff --git a/NEWS b/NEWS index c9531b0..c612360 100644 --- a/NEWS +++ b/NEWS @@ -1,7 +1,8 @@ 1.8.4.dev0 - * Add a monitoring hook for sending backup status to a variety of monitoring services via the + * #715: Add a monitoring hook for sending backup status to a variety of monitoring services via the Apprise library. See the documentation for more information: https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#apprise-hook + * #768: Fix a traceback when an invalid command-line flag or action is used. 1.8.3 * #665: BREAKING: Simplify logging logic as follows: Syslog verbosity is now disabled by diff --git a/borgmatic/logger.py b/borgmatic/logger.py index 5fb67f3..9703924 100644 --- a/borgmatic/logger.py +++ b/borgmatic/logger.py @@ -166,6 +166,8 @@ def configure_logging( Raise FileNotFoundError or PermissionError if the log file could not be opened for writing. ''' + add_custom_log_levels() + if syslog_log_level is None: syslog_log_level = logging.DISABLED if log_file_log_level is None: @@ -173,8 +175,6 @@ def configure_logging( if monitoring_log_level is None: monitoring_log_level = console_log_level - add_custom_log_levels() - # Log certain log levels to console stderr and others to stdout. This supports use cases like # grepping (non-error) output. console_disabled = logging.NullHandler() diff --git a/tests/end-to-end/test_invalid_flag.py b/tests/end-to-end/test_invalid_flag.py new file mode 100644 index 0000000..a813dbf --- /dev/null +++ b/tests/end-to-end/test_invalid_flag.py @@ -0,0 +1,11 @@ +import subprocess +import sys + + +def test_borgmatic_command_with_invalid_flag_shows_error_but_not_traceback(): + output = subprocess.run( + 'borgmatic -v 2 --invalid'.split(' '), stdout=subprocess.PIPE, stderr=subprocess.STDOUT + ).stdout.decode(sys.stdout.encoding) + + assert 'Unrecognized argument' in output + assert 'Traceback' not in output