Skip to content

Commit

Permalink
Make filesystem exceptions subclass from standard library exceptions (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Schamper authored Nov 1, 2024
1 parent ab014f0 commit 2cb8a64
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
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()

0 comments on commit 2cb8a64

Please sign in to comment.