Fix a traceback when an invalid command-line flag or action is used (#768).

This commit is contained in:
Dan Helfman 2023-10-06 21:00:23 -07:00
parent 3eff2c4248
commit c687dafdd2
3 changed files with 15 additions and 3 deletions

3
NEWS
View file

@ -1,7 +1,8 @@
1.8.4.dev0 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: Apprise library. See the documentation for more information:
https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#apprise-hook 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 1.8.3
* #665: BREAKING: Simplify logging logic as follows: Syslog verbosity is now disabled by * #665: BREAKING: Simplify logging logic as follows: Syslog verbosity is now disabled by

View file

@ -166,6 +166,8 @@ def configure_logging(
Raise FileNotFoundError or PermissionError if the log file could not be opened for writing. Raise FileNotFoundError or PermissionError if the log file could not be opened for writing.
''' '''
add_custom_log_levels()
if syslog_log_level is None: if syslog_log_level is None:
syslog_log_level = logging.DISABLED syslog_log_level = logging.DISABLED
if log_file_log_level is None: if log_file_log_level is None:
@ -173,8 +175,6 @@ def configure_logging(
if monitoring_log_level is None: if monitoring_log_level is None:
monitoring_log_level = console_log_level 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 # Log certain log levels to console stderr and others to stdout. This supports use cases like
# grepping (non-error) output. # grepping (non-error) output.
console_disabled = logging.NullHandler() console_disabled = logging.NullHandler()

View file

@ -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