"""Base class for business rule violations.""" from typing import Any class DomainError(Exception): """A business rule was violated. ``code`` identifies the rule; presentation maps it to a translated message. ``field`` optionally names the input field the error belongs to. """ code: str = "domain_error" field: str | None = None def __init__(self, **params: Any) -> None: self.params = params super().__init__(self.code) class InvalidEmailAddress(DomainError): code = "invalid_email" field = "email"