Source code for cion.exceptions

"""Any errors raised by Cion"""
from typing import Any, Optional

__all__ = ("CionException", "ValidatorError", "ValidationError")


[docs]class CionException(Exception): """Base class for all exceptions raised by Cion"""
[docs]class ValidatorError(CionException): """Exception raised by a validator""" message: str #: The message that the validator raised
[docs] def __init__(self, message: str) -> None: self.message = message super().__init__(message)
Errors = dict[str, list[str]] ValidData = dict[str, Any]
[docs]class ValidationError(CionException): """Error raised when validating data""" errors: Errors #: A dictionary containing all of the errors data: Optional[ValidData] = None #: Contains all of the validated data
[docs] def __init__(self, errors: Errors, valid_data: ValidData) -> None: self.errors = errors self.data = valid_data super().__init__(f"Errors were raised: {dict(self.errors)}")
def __repr__(self) -> str: return f"<{self.__class__.__name__} errors={self.errors} data={self.data}>"