Skip to main content

sochdb_query/sql/
error.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2// SochDB - LLM-Optimized Embedded Database
3// Copyright (C) 2026 Sushanth Reddy Vanagala (https://github.com/sushanthpy)
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU Affero General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU Affero General Public License for more details.
14//
15// You should have received a copy of the GNU Affero General Public License
16// along with this program. If not, see <https://www.gnu.org/licenses/>.
17
18//! SQL-specific error types
19
20use thiserror::Error;
21
22/// SQL execution errors
23#[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>;