Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return descriptive error when target tools point to a non-existing file #702

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions dissect/target/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,7 @@ class RegistryCorruptError(RegistryError):

class ConfigurationParsingError(Error):
"""An error occurred during configuration parsing."""


class TargetPathNotFoundError(TargetError):
"""The path to the target does not exist."""
7 changes: 7 additions & 0 deletions dissect/target/loaders/raw.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
from pathlib import Path

from dissect.target import container
from dissect.target.exceptions import TargetPathNotFoundError
from dissect.target.loader import Loader
from dissect.target.target import Target


class RawLoader(Loader):
"""Load raw container files such as disk images."""

def __init__(self, path: Path, **kwargs):
if not path.exists():
raise TargetPathNotFoundError("Provided target path does not exist")

super().__init__(path, **kwargs)

@staticmethod
def detect(path: Path) -> bool:
return not path.is_dir()
Expand Down
7 changes: 6 additions & 1 deletion dissect/target/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
PluginError,
PluginNotFoundError,
TargetError,
TargetPathNotFoundError,
UnsupportedPluginError,
VolumeSystemError,
)
Expand Down Expand Up @@ -284,7 +285,11 @@ def _find(find_path: Path, parsed_path: Optional[urllib.parse.ParseResult]):
try:
ldr = loader_cls(sub_entry, parsed_path=parsed_path)
except Exception as e:
getlogger(sub_entry).error("Failed to initiate loader: %s", e)
message = "Failed to initiate loader: %s"
if isinstance(e, TargetPathNotFoundError):
message = "%s"

getlogger(sub_entry).error(message, e)
getlogger(sub_entry).debug("", exc_info=e)
continue

Expand Down