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("savepoint '{0}' does not exist")]
77    SavepointNotFound(String),
78
79    #[error("subquery must return exactly one column")]
80    SubqueryMultipleColumns,
81
82    #[error("scalar subquery returned more than one row")]
83    SubqueryMultipleRows,
84
85    #[error("query returned no rows")]
86    QueryReturnedNoRows,
87
88    #[error("parameter count mismatch: expected {expected}, got {got}")]
89    ParameterCountMismatch { expected: usize, got: usize },
90
91    #[error("compound column count mismatch: left has {left}, right has {right}")]
92    CompoundColumnCountMismatch { left: usize, right: usize },
93
94    #[error("CTE '{name}' column alias count mismatch: expected {expected}, got {got}")]
95    CteColumnAliasMismatch {
96        name: String,
97        expected: usize,
98        got: usize,
99    },
100
101    #[error("duplicate CTE name: '{0}'")]
102    DuplicateCteName(String),
103
104    #[error("recursive CTE '{0}' requires UNION or UNION ALL")]
105    RecursiveCteNoUnion(String),
106
107    #[error("recursive CTE '{0}' exceeded maximum iterations ({1})")]
108    RecursiveCteMaxIterations(String, usize),
109
110    #[error("window function '{0}' requires ORDER BY")]
111    WindowFunctionRequiresOrderBy(String),
112
113    #[error("view '{0}' not found")]
114    ViewNotFound(String),
115
116    #[error("view '{0}' already exists")]
117    ViewAlreadyExists(String),
118
119    #[error("cannot modify view '{0}'")]
120    CannotModifyView(String),
121
122    #[error("circular or too deeply nested view reference: '{0}'")]
123    CircularViewReference(String),
124
125    #[error("storage error: {0}")]
126    Storage(#[from] citadel_core::Error),
127
128    #[error("invalid DATE literal: {0}")]
129    InvalidDateLiteral(String),
130
131    #[error("invalid TIME literal: {0}")]
132    InvalidTimeLiteral(String),
133
134    #[error("invalid TIMESTAMP literal: {0}")]
135    InvalidTimestampLiteral(String),
136
137    #[error("invalid INTERVAL literal: {0}")]
138    InvalidIntervalLiteral(String),
139
140    #[error("invalid EXTRACT field: {0}")]
141    InvalidExtractField(String),
142
143    #[error("invalid DATE_TRUNC unit: {0}")]
144    InvalidDateTruncUnit(String),
145
146    #[error("time zone not supported: {0}")]
147    TimeZoneUnsupported(String),
148
149    #[error("invalid timezone: {0}")]
150    InvalidTimezone(String),
151}