1#[derive(Debug, Clone, PartialEq)]
3pub enum CatalogError {
4 TableAlreadyExists(String),
5 TableNotFound {
6 table_name: String,
7 },
8 ColumnAlreadyExists(String),
9 ColumnNotFound {
10 column_name: String,
11 table_name: String,
12 },
13 SchemaAlreadyExists(String),
14 SchemaNotFound(String),
15 SchemaNotEmpty(String),
16 RoleAlreadyExists(String),
17 RoleNotFound(String),
18 DomainAlreadyExists(String),
20 DomainNotFound(String),
21 DomainInUse {
22 domain_name: String,
23 dependent_columns: Vec<(String, String)>, },
25 SequenceAlreadyExists(String),
26 SequenceNotFound(String),
27 SequenceInUse {
28 sequence_name: String,
29 dependent_columns: Vec<(String, String)>, },
31 TypeAlreadyExists(String),
32 TypeNotFound(String),
33 TypeInUse(String),
34 CollationAlreadyExists(String),
35 CollationNotFound(String),
36 CharacterSetAlreadyExists(String),
37 CharacterSetNotFound(String),
38 TranslationAlreadyExists(String),
39 TranslationNotFound(String),
40 ViewAlreadyExists(String),
41 ViewNotFound(String),
42 ViewInUse {
43 view_name: String,
44 dependent_views: Vec<String>,
45 },
46 TriggerAlreadyExists(String),
47 TriggerNotFound(String),
48 AssertionAlreadyExists(String),
49 AssertionNotFound(String),
50 FunctionAlreadyExists(String),
51 FunctionNotFound(String),
52 ProcedureAlreadyExists(String),
53 ProcedureNotFound(String),
54 ConstraintAlreadyExists(String),
55 ConstraintNotFound(String),
56 IndexAlreadyExists {
57 index_name: String,
58 table_name: String,
59 },
60 IndexNotFound {
61 index_name: String,
62 table_name: String,
63 },
64 CircularForeignKey {
65 table_name: String,
66 message: String,
67 },
68}
69
70impl std::fmt::Display for CatalogError {
71 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
72 use vibesql_l10n::vibe_msg;
73 match self {
74 CatalogError::TableAlreadyExists(name) => {
75 write!(f, "{}", vibe_msg!("catalog-table-already-exists", name = name.as_str()))
76 }
77 CatalogError::TableNotFound { table_name } => {
78 write!(
79 f,
80 "{}",
81 vibe_msg!("catalog-table-not-found", table_name = table_name.as_str())
82 )
83 }
84 CatalogError::ColumnAlreadyExists(name) => {
85 write!(f, "{}", vibe_msg!("catalog-column-already-exists", name = name.as_str()))
86 }
87 CatalogError::ColumnNotFound { column_name, table_name } => {
88 write!(
89 f,
90 "{}",
91 vibe_msg!(
92 "catalog-column-not-found",
93 column_name = column_name.as_str(),
94 table_name = table_name.as_str()
95 )
96 )
97 }
98 CatalogError::SchemaAlreadyExists(name) => {
99 write!(f, "{}", vibe_msg!("catalog-schema-already-exists", name = name.as_str()))
100 }
101 CatalogError::SchemaNotFound(name) => {
102 write!(f, "{}", vibe_msg!("catalog-schema-not-found", name = name.as_str()))
103 }
104 CatalogError::SchemaNotEmpty(name) => {
105 write!(f, "{}", vibe_msg!("catalog-schema-not-empty", name = name.as_str()))
106 }
107 CatalogError::RoleAlreadyExists(name) => {
108 write!(f, "{}", vibe_msg!("catalog-role-already-exists", name = name.as_str()))
109 }
110 CatalogError::RoleNotFound(name) => {
111 write!(f, "{}", vibe_msg!("catalog-role-not-found", name = name.as_str()))
112 }
113 CatalogError::DomainAlreadyExists(name) => {
114 write!(f, "{}", vibe_msg!("catalog-domain-already-exists", name = name.as_str()))
115 }
116 CatalogError::DomainNotFound(name) => {
117 write!(f, "{}", vibe_msg!("catalog-domain-not-found", name = name.as_str()))
118 }
119 CatalogError::DomainInUse { domain_name, dependent_columns } => {
120 let columns = dependent_columns
121 .iter()
122 .map(|(t, c)| format!("{}.{}", t, c))
123 .collect::<Vec<_>>()
124 .join(", ");
125 write!(
126 f,
127 "{}",
128 vibe_msg!(
129 "catalog-domain-in-use",
130 domain_name = domain_name.as_str(),
131 count = dependent_columns.len() as i64,
132 columns = columns.as_str()
133 )
134 )
135 }
136 CatalogError::SequenceAlreadyExists(name) => {
137 write!(f, "{}", vibe_msg!("catalog-sequence-already-exists", name = name.as_str()))
138 }
139 CatalogError::SequenceNotFound(name) => {
140 write!(f, "{}", vibe_msg!("catalog-sequence-not-found", name = name.as_str()))
141 }
142 CatalogError::SequenceInUse { sequence_name, dependent_columns } => {
143 let columns = dependent_columns
144 .iter()
145 .map(|(t, c)| format!("{}.{}", t, c))
146 .collect::<Vec<_>>()
147 .join(", ");
148 write!(
149 f,
150 "{}",
151 vibe_msg!(
152 "catalog-sequence-in-use",
153 sequence_name = sequence_name.as_str(),
154 count = dependent_columns.len() as i64,
155 columns = columns.as_str()
156 )
157 )
158 }
159 CatalogError::TypeAlreadyExists(name) => {
160 write!(f, "{}", vibe_msg!("catalog-type-already-exists", name = name.as_str()))
161 }
162 CatalogError::TypeNotFound(name) => {
163 write!(f, "{}", vibe_msg!("catalog-type-not-found", name = name.as_str()))
164 }
165 CatalogError::TypeInUse(name) => {
166 write!(f, "{}", vibe_msg!("catalog-type-in-use", name = name.as_str()))
167 }
168 CatalogError::CollationAlreadyExists(name) => {
169 write!(f, "{}", vibe_msg!("catalog-collation-already-exists", name = name.as_str()))
170 }
171 CatalogError::CollationNotFound(name) => {
172 write!(f, "{}", vibe_msg!("catalog-collation-not-found", name = name.as_str()))
173 }
174 CatalogError::CharacterSetAlreadyExists(name) => {
175 write!(
176 f,
177 "{}",
178 vibe_msg!("catalog-character-set-already-exists", name = name.as_str())
179 )
180 }
181 CatalogError::CharacterSetNotFound(name) => {
182 write!(f, "{}", vibe_msg!("catalog-character-set-not-found", name = name.as_str()))
183 }
184 CatalogError::TranslationAlreadyExists(name) => {
185 write!(
186 f,
187 "{}",
188 vibe_msg!("catalog-translation-already-exists", name = name.as_str())
189 )
190 }
191 CatalogError::TranslationNotFound(name) => {
192 write!(f, "{}", vibe_msg!("catalog-translation-not-found", name = name.as_str()))
193 }
194 CatalogError::ViewAlreadyExists(name) => {
195 write!(f, "{}", vibe_msg!("catalog-view-already-exists", name = name.as_str()))
196 }
197 CatalogError::ViewNotFound(name) => {
198 write!(f, "{}", vibe_msg!("catalog-view-not-found", name = name.as_str()))
199 }
200 CatalogError::ViewInUse { view_name, dependent_views } => {
201 let views = dependent_views.join(", ");
202 write!(
203 f,
204 "{}",
205 vibe_msg!(
206 "catalog-view-in-use",
207 view_name = view_name.as_str(),
208 count = dependent_views.len() as i64,
209 views = views.as_str()
210 )
211 )
212 }
213 CatalogError::TriggerAlreadyExists(name) => {
214 write!(f, "{}", vibe_msg!("catalog-trigger-already-exists", name = name.as_str()))
215 }
216 CatalogError::TriggerNotFound(name) => {
217 write!(f, "{}", vibe_msg!("catalog-trigger-not-found", name = name.as_str()))
218 }
219 CatalogError::AssertionAlreadyExists(name) => {
220 write!(f, "{}", vibe_msg!("catalog-assertion-already-exists", name = name.as_str()))
221 }
222 CatalogError::AssertionNotFound(name) => {
223 write!(f, "{}", vibe_msg!("catalog-assertion-not-found", name = name.as_str()))
224 }
225 CatalogError::FunctionAlreadyExists(name) => {
226 write!(f, "{}", vibe_msg!("catalog-function-already-exists", name = name.as_str()))
227 }
228 CatalogError::FunctionNotFound(name) => {
229 write!(f, "{}", vibe_msg!("catalog-function-not-found", name = name.as_str()))
230 }
231 CatalogError::ProcedureAlreadyExists(name) => {
232 write!(f, "{}", vibe_msg!("catalog-procedure-already-exists", name = name.as_str()))
233 }
234 CatalogError::ProcedureNotFound(name) => {
235 write!(f, "{}", vibe_msg!("catalog-procedure-not-found", name = name.as_str()))
236 }
237 CatalogError::ConstraintAlreadyExists(name) => {
238 write!(
239 f,
240 "{}",
241 vibe_msg!("catalog-constraint-already-exists", name = name.as_str())
242 )
243 }
244 CatalogError::ConstraintNotFound(name) => {
245 write!(f, "{}", vibe_msg!("catalog-constraint-not-found", name = name.as_str()))
246 }
247 CatalogError::IndexAlreadyExists { index_name, table_name } => {
248 write!(
249 f,
250 "{}",
251 vibe_msg!(
252 "catalog-index-already-exists",
253 index_name = index_name.as_str(),
254 table_name = table_name.as_str()
255 )
256 )
257 }
258 CatalogError::IndexNotFound { index_name, table_name } => {
259 write!(
260 f,
261 "{}",
262 vibe_msg!(
263 "catalog-index-not-found",
264 index_name = index_name.as_str(),
265 table_name = table_name.as_str()
266 )
267 )
268 }
269 CatalogError::CircularForeignKey { table_name, message } => {
270 write!(
271 f,
272 "{}",
273 vibe_msg!(
274 "catalog-circular-foreign-key",
275 table_name = table_name.as_str(),
276 message = message.as_str()
277 )
278 )
279 }
280 }
281 }
282}
283
284impl std::error::Error for CatalogError {}