diff --git a/borgmatic/hooks/data_source/config.py b/borgmatic/hooks/data_source/config.py index 194ec1be..9a794853 100644 --- a/borgmatic/hooks/data_source/config.py +++ b/borgmatic/hooks/data_source/config.py @@ -64,7 +64,10 @@ def get_ip_from_container(container): logger.debug(f"Could not find container '{container}' with engine '{engine}'") continue # Container does not exist - network_data = json.loads(output.strip()) + try: + network_data = json.loads(output.strip()) + except json.JSONDecodeError as e: + raise ValueError(f'Could not decode JSON output from {engine}') from e main_ip = network_data.get('IPAddress') if main_ip: return main_ip diff --git a/tests/unit/hooks/data_source/test_config.py b/tests/unit/hooks/data_source/test_config.py index ae3198d0..5b583231 100644 --- a/tests/unit/hooks/data_source/test_config.py +++ b/tests/unit/hooks/data_source/test_config.py @@ -91,3 +91,13 @@ def test_get_container_ip_container_no_network(): with pytest.raises(ValueError) as exc_info: config.get_ip_from_container('yolo') assert 'Could not determine ip address for container' in str(exc_info.value) + + +def test_get_container_ip_broken_output(): + flexmock(config.shutil).should_receive('which').and_return(None).and_return('/usr/bin/podman') + + flexmock(config).should_receive('execute_command_and_capture_output').and_return('abc') + + with pytest.raises(ValueError) as exc_info: + config.get_ip_from_container('yolo') + assert 'Could not decode JSON output' in str(exc_info.value)