Skip to content

Rule Violated Error

rule_violated_error

Concrete throwable error for business rule violations.

Defines RuleViolatedError, the leaf class that code MUST use when
constructing and raising a rule violation. RuleViolationError is the
abstract base class — it cannot be directly instantiated.

Extends RuleViolationError (which extends RuntimeErrorMixin and
Error[object]).

RuleViolatedError

Bases: RuleViolationError

A concrete rule violation that can be thrown when a business rule is violated.

This is the concrete leaf class for rule violations. RuleViolationError
is the abstract base; code that constructs and raises a rule violation
MUST use RuleViolatedError.

Example
from forging_blocks.foundation.errors import ErrorMessage

err = RuleViolatedError(ErrorMessage("Account must be active"))
assert isinstance(err, RuntimeError)
raise err
Source code in src/forging_blocks/foundation/errors/rule_violations/rule_violated_error.py
class RuleViolatedError(RuleViolationError):
    """A concrete rule violation that can be thrown when a business rule is violated.

    This is the concrete leaf class for rule violations. ``RuleViolationError``
    is the abstract base; code that constructs and raises a rule violation
    MUST use ``RuleViolatedError``.

    Example:
        ```python
        from forging_blocks.foundation.errors import ErrorMessage

        err = RuleViolatedError(ErrorMessage("Account must be active"))
        assert isinstance(err, RuntimeError)
        raise err
        ```
    """