sochdb_query/sql/
error.rs1use thiserror::Error;
18
19#[derive(Error, Debug, Clone)]
21pub enum SqlError {
22 #[error("Parse error at line {line}, column {column}: {message}")]
23 ParseError {
24 message: String,
25 line: usize,
26 column: usize,
27 },
28
29 #[error("Lexer error: {0}")]
30 LexError(String),
31
32 #[error("Table not found: {0}")]
33 TableNotFound(String),
34
35 #[error("Column not found: {0}")]
36 ColumnNotFound(String),
37
38 #[error("Type error: {0}")]
39 TypeError(String),
40
41 #[error("Constraint violation: {0}")]
42 ConstraintViolation(String),
43
44 #[error("Transaction error: {0}")]
45 TransactionError(String),
46
47 #[error("Not implemented: {0}")]
48 NotImplemented(String),
49
50 #[error("Execution error: {0}")]
51 ExecutionError(String),
52
53 #[error("Invalid argument: {0}")]
54 InvalidArgument(String),
55}
56
57impl SqlError {
58 pub fn from_parse_errors(errors: Vec<super::parser::ParseError>) -> Self {
59 if let Some(first) = errors.first() {
60 SqlError::ParseError {
61 message: first.message.clone(),
62 line: first.span.line,
63 column: first.span.column,
64 }
65 } else {
66 SqlError::ParseError {
67 message: "Unknown parse error".to_string(),
68 line: 0,
69 column: 0,
70 }
71 }
72 }
73}
74
75pub type SqlResult<T> = std::result::Result<T, SqlError>;