Module pedantic.decorators.fn_deco_validate.exceptions

Classes

class ConversionError (msg: str)
Expand source code
class ConversionError(ValidateException):
    """ Is raised if a type cast failed. """

Is raised if a type cast failed.

Ancestors

class ExceptionDictKey
Expand source code
class ExceptionDictKey:
    VALUE = 'VALUE'
    MESSAGE = 'MESSAGE'
    PARAMETER = 'PARAMETER'
    VALIDATOR = 'VALIDATOR'

Class variables

var MESSAGE

The type of the None singleton.

var PARAMETER

The type of the None singleton.

var VALIDATOR

The type of the None singleton.

var VALUE

The type of the None singleton.

class InvalidHeader (msg: str,
parameter_name: str,
value: Any | None = None,
validator_name: str | None = None)
Expand source code
class InvalidHeader(ParameterException):
    """ Is raised if there is a validation error in a FlaskHeaderParameter. """

Is raised if there is a validation error in a FlaskHeaderParameter.

Ancestors

Inherited members

class ParameterException (msg: str,
parameter_name: str,
value: Any | None = None,
validator_name: str | None = None)
Expand source code
class ParameterException(ValidateException):
    """ An exception that is raised inside a Parameter. """

    def __init__(self, msg: str, parameter_name: str,
                 value: Optional[Any] = None, validator_name: Optional[str] = None) -> None:
        super().__init__(msg=msg)
        self.validator_name = validator_name
        self.parameter_name = parameter_name
        self.value = value

    @classmethod
    def from_validator_exception(cls, exception: ValidatorException, parameter_name: str = '') -> 'ParameterException':
        """ Creates a parameter exception from a validator exception. """
        return cls(
            value=exception.value,
            msg=exception.message,
            validator_name=exception.validator_name,
            parameter_name=parameter_name or exception.parameter_name,
        )

    def __str__(self) -> str:
        return str(self.to_dict)

    @property
    def to_dict(self) -> Dict[str, str]:
        return {
            ExceptionDictKey.VALUE: str(self.value),
            ExceptionDictKey.MESSAGE: self.message,
            ExceptionDictKey.VALIDATOR: self.validator_name,
            ExceptionDictKey.PARAMETER: self.parameter_name,
        }

An exception that is raised inside a Parameter.

Ancestors

Subclasses

Static methods

def from_validator_exception(exception: ValidatorException,
parameter_name: str = '') ‑> ParameterException

Creates a parameter exception from a validator exception.

Instance variables

prop to_dict : Dict[str, str]
Expand source code
@property
def to_dict(self) -> Dict[str, str]:
    return {
        ExceptionDictKey.VALUE: str(self.value),
        ExceptionDictKey.MESSAGE: self.message,
        ExceptionDictKey.VALIDATOR: self.validator_name,
        ExceptionDictKey.PARAMETER: self.parameter_name,
    }
class TooManyArguments (msg: str)
Expand source code
class TooManyArguments(ValidateException):
    """ Is raised if the function got more arguments than expected. """

Is raised if the function got more arguments than expected.

Ancestors

class ValidateException (msg: str)
Expand source code
class ValidateException(Exception):
    """ The base class for all exception thrown by the validate decorator. """

    def __init__(self, msg: str) -> None:
        self.message = msg

The base class for all exception thrown by the validate decorator.

Ancestors

  • builtins.Exception
  • builtins.BaseException

Subclasses

class ValidatorException (msg: str, validator_name: str, value: Any, parameter_name: str = '')
Expand source code
class ValidatorException(ValidateException):
    """ An exception that is raised inside the validate() function of a Validator. """

    def __init__(self, msg: str, validator_name: str, value: Any, parameter_name: str = '') -> None:
        super().__init__(msg=msg)
        self.validator_name = validator_name
        self.value = value
        self.parameter_name = parameter_name

    def __str__(self) -> str:
        return f'{self.validator_name}: {self.message} Value: {self.value}'

An exception that is raised inside the validate() function of a Validator.

Ancestors