Skip to main content

citadel_sql/
error.rs

1use thiserror::Error;
2
3pub type Result<T> = std::result::Result<T, SqlError>;
4
5#[derive(Debug, Error)]
6pub enum SqlError {
7    #[error("parse error: {0}")]
8    Parse(String),
9
10    #[error("table '{0}' not found")]
11    TableNotFound(String),
12
13    #[error("table '{0}' already exists")]
14    TableAlreadyExists(String),
15
16    #[error("column '{0}' not found")]
17    ColumnNotFound(String),
18
19    #[error("duplicate primary key")]
20    DuplicateKey,
21
22    #[error("NOT NULL constraint failed: {0}")]
23    NotNullViolation(String),
24
25    #[error("type mismatch: expected {expected}, got {got}")]
26    TypeMismatch { expected: String, got: String },
27
28    #[error("primary key required")]
29    PrimaryKeyRequired,
30
31    #[error("duplicate column: {0}")]
32    DuplicateColumn(String),
33
34    #[error("row too large: encoded size {size} exceeds limit {max}")]
35    RowTooLarge { size: usize, max: usize },
36
37    #[error("key too large: encoded size {size} exceeds limit {max}")]
38    KeyTooLarge { size: usize, max: usize },
39
40    #[error("unsupported: {0}")]
41    Unsupported(String),
42
43    #[error("invalid value: {0}")]
44    InvalidValue(String),
45
46    #[error("division by zero")]
47    DivisionByZero,
48
49    #[error("integer overflow")]
50    IntegerOverflow,
51
52    #[error("column '{0}' is ambiguous")]
53    AmbiguousColumn(String),
54
55    #[error("index '{0}' not found")]
56    IndexNotFound(String),
57
58    #[error("index '{0}' already exists")]
59    IndexAlreadyExists(String),
60
61    #[error("unique constraint violated on index '{0}'")]
62    UniqueViolation(String),
63
64    #[error("CHECK constraint failed: {0}")]
65    CheckViolation(String),
66
67    #[error("FOREIGN KEY constraint violated: {0}")]
68    ForeignKeyViolation(String),
69
70    #[error("transaction already active")]
71    TransactionAlreadyActive,
72
73    #[error("no active transaction")]
74    NoActiveTransaction,
75
76    #[error("subquery must return exactly one column")]
77    SubqueryMultipleColumns,
78
79    #[error("scalar subquery returned more than one row")]
80    SubqueryMultipleRows,
81
82    #[error("parameter count mismatch: expected {expected}, got {got}")]
83    ParameterCountMismatch { expected: usize, got: usize },
84
85    #[error("compound column count mismatch: left has {left}, right has {right}")]
86    CompoundColumnCountMismatch { left: usize, right: usize },
87
88    #[error("CTE '{name}' column alias count mismatch: expected {expected}, got {got}")]
89    CteColumnAliasMismatch {
90        name: String,
91        expected: usize,
92        got: usize,
93    },
94
95    #[error("duplicate CTE name: '{0}'")]
96    DuplicateCteName(String),
97
98    #[error("recursive CTE '{0}' requires UNION or UNION ALL")]
99    RecursiveCteNoUnion(String),
100
101    #[error("recursive CTE '{0}' exceeded maximum iterations ({1})")]
102    RecursiveCteMaxIterations(String, usize),
103
104    #[error("storage error: {0}")]
105    Storage(#[from] citadel_core::Error),
106}