Source code for minos.common.exceptions

from __future__ import (
    annotations,
)

from typing import (
    Any,
    Type,
)


[docs]class MinosException(Exception): """Exception class for import packages or modules""" __slots__ = "_message"
[docs] def __init__(self, error_message: str): self._message = error_message
def __repr__(self): return f"{type(self).__name__}(message={repr(self._message)})" def __str__(self) -> str: """represent in a string format the error message passed during the instantiation""" return self._message
[docs]class NotProvidedException(MinosException): """Exception to be raised when a dependency is needed but not provided."""
[docs]class MinosImportException(MinosException): pass
[docs]class MinosProtocolException(MinosException): pass
[docs]class MinosMessageException(MinosException): pass
[docs]class MinosConfigException(MinosException): """Base config exception."""
[docs]class MinosBrokerException(MinosException): """Base broker exception"""
[docs]class MinosHandlerException(MinosException): """Base handler exception"""
[docs]class MinosLockException(MinosException): """Base lock exception"""
[docs]class MinosModelException(MinosException): """Exception to be raised when some mandatory condition is not satisfied by a model.""" pass
[docs]class EmptyMinosModelSequenceException(MinosModelException): """Exception to be raised when a sequence must be not empty, but it is empty.""" pass
[docs]class MultiTypeMinosModelSequenceException(MinosModelException): """Exception to be raised when a sequence doesn't satisfy the condition to have the same type for each item.""" pass
[docs]class MinosModelAttributeException(MinosException): """Base model attributes exception.""" pass
[docs]class MinosReqAttributeException(MinosModelAttributeException): """Exception to be raised when some required attributes are not provided.""" pass
[docs]class MinosTypeAttributeException(MinosModelAttributeException): """Exception to be raised when there are any mismatching between the expected and observed attribute type."""
[docs] def __init__(self, name: str, target_type: Type, value: Any): self.name = name self.target_type = target_type self.value = value super().__init__( f"The {target_type!r} expected type for {name!r} does not match with " f"the given data type: {type(value)!r} ({value!r})" )
[docs]class MinosMalformedAttributeException(MinosModelAttributeException): """Exception to be raised when there are any kind of problems with the type definition.""" pass
[docs]class MinosParseAttributeException(MinosModelAttributeException): """Exception to be raised when there are any kind of problems with the parsing logic."""
[docs] def __init__(self, name: str, value: Any, exception: Exception): self.name = name self.value = value self.exception = exception super().__init__(f"{repr(exception)} was raised while parsing {repr(name)} field with {repr(value)} value.")
[docs]class MinosAttributeValidationException(MinosModelAttributeException): """Exception to be raised when some fields are not valid."""
[docs] def __init__(self, name: str, value: Any): self.name = name self.value = value super().__init__(f"{repr(value)} value does not pass the {repr(name)} field validation.")
[docs]class DataDecoderException(MinosModelException): """Base data decoder exception."""
[docs]class DataDecoderMalformedTypeException(DataDecoderException): """Exception to be raised when malformed types are provided."""
[docs]class DataDecoderRequiredValueException(DataDecoderException): """Exception to be raised when required values are not provided."""
[docs]class DataDecoderTypeException(DataDecoderException): """Exception to be raised when expected and provided types do not match."""
[docs] def __init__(self, target_type: Type, value: Any): self.target_type = target_type self.value = value super().__init__( f"The {target_type!r} expected type does not match the given data type: {type(value)!r} ({value!r})" )