sochdb_query/sql/
error.rs

1// Copyright 2025 Sushanth (https://github.com/sushanthpy)
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! SQL-specific error types
16
17use thiserror::Error;
18
19/// SQL execution errors
20#[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>;