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

Make filesystem exceptions subclass from standard library exceptions #928

Merged
merged 4 commits into from
Nov 1, 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
6 changes: 3 additions & 3 deletions dissect/target/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ class PluginNotFoundError(PluginError):
"""Plugin cannot be found."""


class FileNotFoundError(FilesystemError):
class FileNotFoundError(FilesystemError, FileNotFoundError):
"""The requested path could not be found."""


class IsADirectoryError(FilesystemError):
class IsADirectoryError(FilesystemError, IsADirectoryError):
"""The entry is a directory."""


class NotADirectoryError(FilesystemError):
class NotADirectoryError(FilesystemError, NotADirectoryError):
"""The entry is not a directory."""


Expand Down
19 changes: 19 additions & 0 deletions tests/test_exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pytest

from dissect.target import exceptions


@pytest.mark.parametrize(
"exc, std",
[
(exceptions.FileNotFoundError, FileNotFoundError),
(exceptions.IsADirectoryError, IsADirectoryError),
(exceptions.NotADirectoryError, NotADirectoryError),
],
)
def test_filesystem_error_subclass(exc: exceptions.Error, std: Exception) -> None:
assert issubclass(exc, (std, exceptions.FilesystemError))
assert isinstance(exc(), (std, exceptions.FilesystemError))

with pytest.raises(std):
raise exc()
Loading