from collections.abc import Generator
from contextlib import contextmanager
from typing import Any, Final
__all__ = (
"SQLSTATE_EXCEPTION_MAP",
"CheckViolationError",
"ConfigResolverError",
"ConnectionTimeoutError",
"DataError",
"DatabaseConnectionError",
"DeadlockError",
"DialectNotSupportedError",
"EventChannelError",
"FileNotFoundInStorageError",
"ForeignKeyViolationError",
"ImproperConfigurationError",
"IntegrityError",
"InvalidVersionFormatError",
"MigrationError",
"MissingDependencyError",
"MultipleResultsFoundError",
"NotFoundError",
"NotNullViolationError",
"OperationalError",
"OutOfOrderMigrationError",
"PermissionDeniedError",
"QueryTimeoutError",
"RepositoryError",
"SQLBuilderError",
"SQLConversionError",
"SQLFileNotFoundError",
"SQLFileParseError",
"SQLParsingError",
"SQLSpecError",
"SQLStatementNotFoundError",
"SerializationConflictError",
"SerializationError",
"SquashValidationError",
"StackExecutionError",
"StorageCapabilityError",
"StorageOperationFailedError",
"TransactionError",
"TransactionRetryError",
"UniqueViolationError",
"map_sqlstate_to_exception",
)
STACK_SQL_PREVIEW_LIMIT: Final[int] = 120
class SQLSpecError(Exception):
"""Base exception class for SQLSpec exceptions."""
detail: str = ""
def __init__(self, *args: Any, detail: str = "") -> None:
"""Initialize SQLSpecError.
Args:
*args: args are converted to :class:`str` before passing to :class:`Exception`
detail: detail of the exception.
"""
str_args = [str(arg) for arg in args if arg]
if not detail:
detail = str_args[0] if str_args else ""
self.detail = detail
if detail and detail not in str_args:
str_args = [detail, *str_args]
super().__init__(*str_args)