diff --git a/ipfshttpclient/exceptions.py b/ipfshttpclient/exceptions.py index 469859b3..02b773e2 100644 --- a/ipfshttpclient/exceptions.py +++ b/ipfshttpclient/exceptions.py @@ -115,15 +115,15 @@ def __init__(self, encoder_name: str, original: Exception) -> None: # filescanner.py # ################## -class MatcherSpecInvalidError(TypeError): +class MatcherSpecInvalidError(Error, TypeError): """ An attempt was made to build a matcher using matcher_from_spec, but an invalid specification was provided. """ - def __init__(self, matcher_class: type, invalid_spec: ty.Any) -> None: + def __init__(self, invalid_spec: ty.Any) -> None: super().__init__( - f"Don't know how to create a {matcher_class.__name__} from spec {invalid_spec!r}" + f"Don't know how to create a Matcher from spec {invalid_spec!r}" ) diff --git a/ipfshttpclient/filescanner.py b/ipfshttpclient/filescanner.py index ac27cc8c..c0a44835 100644 --- a/ipfshttpclient/filescanner.py +++ b/ipfshttpclient/filescanner.py @@ -497,7 +497,7 @@ def _recursive_matcher_from_spec(spec: match_spec_t[AnyStr], *, else: # Actual list of matchers (plural) return MetaMatcher(matchers) else: - raise MatcherSpecInvalidError(Matcher, spec) + raise MatcherSpecInvalidError(spec) class walk(ty.Generator[FSNodeEntry[AnyStr], ty.Any, None], ty.Generic[AnyStr]): diff --git a/test/unit/test_exceptions.py b/test/unit/test_exceptions.py new file mode 100644 index 00000000..ec6ac633 --- /dev/null +++ b/test/unit/test_exceptions.py @@ -0,0 +1,18 @@ + +from ipfshttpclient.exceptions import MatcherSpecInvalidError, Error +from ipfshttpclient.filescanner import Matcher + + +def test_matcher_spec_invalid_error_message(): + ex = MatcherSpecInvalidError('junk') + assert ex.args[0] == f"Don't know how to create a {Matcher.__name__} from spec 'junk'" + + +def test_matcher_spec_invalid_error_multiple_inheritance(): + ex = MatcherSpecInvalidError('wrong') + + # Base class of all exceptions in this library + assert isinstance(ex, Error) + + # Base class of type errors + assert isinstance(ex, TypeError)