diff --git a/dissect/target/exceptions.py b/dissect/target/exceptions.py index e52d23f25..77dc540b8 100644 --- a/dissect/target/exceptions.py +++ b/dissect/target/exceptions.py @@ -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.""" diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py new file mode 100644 index 000000000..29e049430 --- /dev/null +++ b/tests/test_exceptions.py @@ -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()