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