diff --git a/dissect/target/target.py b/dissect/target/target.py index c3a2ab516..5dd6f81ec 100644 --- a/dissect/target/target.py +++ b/dissect/target/target.py @@ -303,13 +303,14 @@ def _find(find_path: Path, parsed_path: Optional[urllib.parse.ParseResult]): try: # Attempt to load the target using this loader target = cls._load(sub_entry, ldr) + except Exception as e: + getlogger(sub_entry).error("Failed to load target with loader %s", ldr, exc_info=e) + continue + else: loaded = True at_least_one_loaded = True yield target - except Exception as e: - getlogger(sub_entry).error("Failed to load target with loader %s", ldr, exc_info=e) - if include_children: try: yield from target.open_children() diff --git a/tests/test_target.py b/tests/test_target.py index 452be25ab..34d5e1098 100644 --- a/tests/test_target.py +++ b/tests/test_target.py @@ -516,3 +516,21 @@ def test_fs_mount_already_there(target_unix: Target, nr_of_fs: int) -> None: assert f"/$fs$/fs{idx}" in target_unix.fs.mounts.keys() assert target_unix.fs.path(f"$fs$/fs{idx}").exists() + + +def test_children_on_invalid_target(caplog: pytest.LogCaptureFixture, tmp_path: Path) -> None: + """test that we don't attempt to load child targets on an invalid target""" + p = tmp_path.joinpath("empty-dir") + p.mkdir() + + mock_loader = Mock() + mock_loader.find_all.return_value = [None] + mock_loader.return_value = None + + with patch.object(loader, "find_loader", return_value=mock_loader): + try: + list(Target.open_all([p], include_children=True)) + except Exception: + pass + + assert "Failed to load child target from None" not in caplog.text