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 #[error("Permission denied: {0}")]
60 PermissionDenied(String),
61}
62
63impl SqlError {
64 pub fn from_parse_errors(errors: Vec<super::parser::ParseError>) -> Self {
65 if let Some(first) = errors.first() {
66 SqlError::ParseError {
67 message: first.message.clone(),
68 line: first.span.line,
69 column: first.span.column,
70 }
71 } else {
72 SqlError::ParseError {
73 message: "Unknown parse error".to_string(),
74 line: 0,
75 column: 0,
76 }
77 }
78 }
79}
80
81pub type SqlResult<T> = std::result::Result<T, SqlError>;