Skip to content

Not Callable Predicate Error

not_callable_predicate_error

Error raised when a specification predicate is not a callable object.

Defines NotCallablePredicateError, raised when an object provided
as a specification predicate is not callable.

NotCallablePredicateError

Bases: ValueErrorMixin, Error[MetadataValueType]

Exception raised when a specification predicate is not callable.

The error message includes the actual type of the predicate that was
provided, helping developers identify and fix the issue.

Attributes:

Name Type Description
message ErrorMessage

Structured error message containing the type name of the invalid predicate.

metadata ErrorMetadata[MetadataValueType]

Optional metadata providing additional context about the error.

context dict[str, MetadataValueType]

Shortcut access to the metadata context dictionary.

Example
error = NotCallablePredicateError(predicate="not_a_function")
raise error
Source code in src/forging_blocks/foundation/errors/not_callable_predicate_error.py
class NotCallablePredicateError(ValueErrorMixin, Error[MetadataValueType]):
    """Exception raised when a specification predicate is not callable.

    The error message includes the actual type of the predicate that was
    provided, helping developers identify and fix the issue.

    Attributes:
        message: Structured error message containing the type name of the invalid predicate.
        metadata: Optional metadata providing additional context about the error.
        context: Shortcut access to the metadata context dictionary.

    Example:
        ```python
        error = NotCallablePredicateError(predicate="not_a_function")
        raise error
        ```


    """

    def __init__(
        self,
        predicate: object,
    ) -> None:
        """Initialize the NotCallablePredicateError with the invalid predicate.

        Args:
            predicate: The object that was provided as a predicate but is not callable.
                The type name of this object will be included in the error message.

        """
        message = ErrorMessage(f"predicate must be Callable and not {type(predicate).__name__}")
        super().__init__(message)

__init__(predicate: object) -> None

Initialize the NotCallablePredicateError with the invalid predicate.

Parameters:

Name Type Description Default
predicate object

The object that was provided as a predicate but is not callable.
The type name of this object will be included in the error message.

required
Source code in src/forging_blocks/foundation/errors/not_callable_predicate_error.py
def __init__(
    self,
    predicate: object,
) -> None:
    """Initialize the NotCallablePredicateError with the invalid predicate.

    Args:
        predicate: The object that was provided as a predicate but is not callable.
            The type name of this object will be included in the error message.

    """
    message = ErrorMessage(f"predicate must be Callable and not {type(predicate).__name__}")
    super().__init__(message)