diff --git a/borgmatic/commands/borgmatic.py b/borgmatic/commands/borgmatic.py index d346662..c1f58ec 100644 --- a/borgmatic/commands/borgmatic.py +++ b/borgmatic/commands/borgmatic.py @@ -404,7 +404,11 @@ def collect_configuration_run_summary_logs(config_filenames, args): yield logging.makeLogRecord(dict(levelno=logging.CRITICAL, msg=error)) if args.extract: - validate.guard_configuration_contains_repository(args.repository, configs) + try: + validate.guard_configuration_contains_repository(args.repository, configs) + except ValueError as error: + yield logging.makeLogRecord(dict(levelno=logging.CRITICAL, msg=error)) + return for config_filename, config in configs.items(): try: diff --git a/tests/unit/commands/test_borgmatic.py b/tests/unit/commands/test_borgmatic.py index 59d879f..5a656f4 100644 --- a/tests/unit/commands/test_borgmatic.py +++ b/tests/unit/commands/test_borgmatic.py @@ -57,7 +57,7 @@ def test_collect_configuration_run_summary_logs_info_for_success(): assert any(log for log in logs if log.levelno == module.logging.INFO) -def test_collect_configuration_run_summary_still_succeeds_when_extract_true(): +def test_collect_configuration_run_summary_logs_info_for_success_with_extract(): flexmock(module.validate).should_receive('parse_configuration').and_return({'test.yaml': {}}) flexmock(module.validate).should_receive('guard_configuration_contains_repository') flexmock(module).should_receive('run_configuration') @@ -68,6 +68,18 @@ def test_collect_configuration_run_summary_still_succeeds_when_extract_true(): assert any(log for log in logs if log.levelno == module.logging.INFO) +def test_collect_configuration_run_summary_logs_critical_for_extract_with_repository_error(): + flexmock(module.validate).should_receive('parse_configuration').and_return({'test.yaml': {}}) + flexmock(module.validate).should_receive('guard_configuration_contains_repository').and_raise( + ValueError + ) + args = flexmock(extract=True, repository='repo') + + logs = tuple(module.collect_configuration_run_summary_logs(('test.yaml',), args=args)) + + assert any(log for log in logs if log.levelno == module.logging.CRITICAL) + + def test_collect_configuration_run_summary_logs_critical_for_parse_error(): flexmock(module.validate).should_receive('parse_configuration').and_raise(ValueError) args = flexmock(extract=False)