use thiserror::Error;
#[derive(Error, Debug, Clone)]
pub enum SqlError {
#[error("Parse error at line {line}, column {column}: {message}")]
ParseError {
message: String,
line: usize,
column: usize,
},
#[error("Lexer error: {0}")]
LexError(String),
#[error("Table not found: {0}")]
TableNotFound(String),
#[error("Column not found: {0}")]
ColumnNotFound(String),
#[error("Type error: {0}")]
TypeError(String),
#[error("Constraint violation: {0}")]
ConstraintViolation(String),
#[error("Transaction error: {0}")]
TransactionError(String),
#[error("Not implemented: {0}")]
NotImplemented(String),
#[error("Execution error: {0}")]
ExecutionError(String),
#[error("Invalid argument: {0}")]
InvalidArgument(String),
#[error("Permission denied: {0}")]
PermissionDenied(String),
}
impl SqlError {
pub fn from_parse_errors(errors: Vec<super::parser::ParseError>) -> Self {
if let Some(first) = errors.first() {
SqlError::ParseError {
message: first.message.clone(),
line: first.span.line,
column: first.span.column,
}
} else {
SqlError::ParseError {
message: "Unknown parse error".to_string(),
line: 0,
column: 0,
}
}
}
}
pub type SqlResult<T> = std::result::Result<T, SqlError>;