Error Modules

This module contains the base class for handing errors in the application. It provides the building blocks for creating error classes that can be used to store errors for specific fields.

class action_triggers.error.base.ErrorBase[source]

Bases: object

A base class for storing errors for a set of fields. For each field, an error can be added using the add_<field_name>_error method.

Parameters:

error_class – The class of the error to raise when the error is not valid.

Example:

class MyError(ErrorBase):
    field_1 = ErrorField("field_1")
    field_2 = ErrorField("field_2")

error = MyError()
error.add_field_1_error("key_1", "message_1")
error.add_field_1_error("key_1", "message_2")
error.add_field_2_error("key_2", "message_3")

error.as_dict()
# {
#     "field_1": {"key_1": ["message_1", "message_2"]},
#     "field_2": {"key_2": ["message_3"]},
# }

# Raises an exception if the error is not valid.
error.is_valid(raise_exception=True)
as_dict() dict[source]

Return the error message as a dictionary.

Returns:

A dictionary containing the errors.

error_class

alias of Exception

is_valid(raise_exception: bool = False) bool[source]

Check if the error is valid.

Parameters:

raise_exception – Whether to raise an exception if raise_exception is True and there are errors.

Returns:

True if the error is valid, False otherwise.

class action_triggers.error.base.ErrorField(field_name)[source]

Bases: object

A class for storing errors for a specific field.

Parameters:

field_name – The name of the field.

add_error(instance, key: str, message: str) None[source]

Adds an error for the field.

Parameters:
  • instance – The instance of the class.

  • key – The key for the error.

  • message – The error message.

class action_triggers.error.base.MetaError(name, bases, dct)[source]

Bases: type

A metaclass for the Error class. This metaclass automatically generates methods for adding errors to the fields of the Error class.