Coverage for snekql/errors.py: 100%
27 statements
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-07 21:13 +0300
« prev ^ index » next coverage.py v7.14.1, created at 2026-06-07 21:13 +0300
1"""Intentional package-originated exception hierarchy for snekql."""
3from __future__ import annotations
6class SnekqlError(Exception):
7 """Base class for all intentional package-originated exceptions.
9 >>> isinstance(ModelDeclarationError("bad model"), SnekqlError)
10 True
11 """
14class ModelError(SnekqlError):
15 """Base class for table model declaration and validation failures."""
18class ModelDeclarationError(ModelError):
19 """Raised when a table model class violates snekql declaration rules."""
22class ModelValidationError(ModelError):
23 """Raised when pending or fetched table model values fail validation."""
26class FrozenModelError(ModelError):
27 """Raised when code attempts to mutate an immutable table model instance."""
30class QueryError(SnekqlError):
31 """Base class for query builder construction and compilation failures."""
34class QueryConstructionError(QueryError):
35 """Raised when query builder methods are used in an invalid sequence."""
38class QueryCompilationError(QueryError):
39 """Raised when a built query cannot be compiled into valid SQLite SQL."""
42class DatabaseRuntimeError(SnekqlError):
43 """Base class for Database and Transaction execution failures."""
46class DatabaseClosedError(DatabaseRuntimeError):
47 """Raised when a closed Database is used for new work."""
50class TransactionClosedError(DatabaseRuntimeError):
51 """Raised when a Transaction is used after it has closed."""
54class PoolTimeoutError(DatabaseRuntimeError):
55 """Raised when acquiring a database connection exceeds the timeout."""
58class DatabaseCloseTimeoutError(DatabaseRuntimeError):
59 """Raised when Database.close cannot finish before its timeout."""
62class DatabaseClosingError(DatabaseRuntimeError):
63 """Raised when new work starts while Database.close is in progress."""
66class ExecutionError(DatabaseRuntimeError):
67 """Database execution failure with query context.
69 >>> error = ExecutionError("failed", sql="SELECT ?", params=(1,))
70 >>> error.sql
71 'SELECT ?'
72 """
74 sql: str
75 params: tuple[object, ...]
77 def __init__(
78 self,
79 message: str,
80 *,
81 sql: str,
82 params: tuple[object, ...],
83 ) -> None:
84 super().__init__(message)
85 self.sql: str = sql
86 self.params: tuple[object, ...] = params
88 def __str__(self) -> str:
89 message = super().__str__()
90 return f"{message} sql={self.sql!r} params={self.params!r}"
93class SchemaError(SnekqlError):
94 """Base class for schema creation and verification failures."""
97class SchemaVerificationError(SchemaError):
98 """Raised when an existing database table drifts from model DDL."""