Menu
Public repository / master
AkurAI-Framework / crates/sqlexec/src/error.rs
Latest change a26d2091b5fd875b4928c72190c7dbf9f37b9252 - feat(sql): add UPDATE and DELETE to parser and executor by Ólafur Búi Ólafsson
//! The executor's error type.
use std::fmt;
use std::io;
use akurai_sql::SqlError;
/// Anything that can go wrong while planning or running a statement.
#[derive(Debug)]
pub enum ExecError {
/// The SQL text failed to parse.
Parse(SqlError),
/// An I/O error bubbled up from the storage layer.
Io(io::Error),
/// `CREATE TABLE` named a table that already exists.
TableExists(String),
/// A statement referenced a table that was never created.
NoSuchTable(String),
/// A column named in a statement is not part of the table's schema.
UnknownColumn(String),
/// `INSERT` supplied a column/value count that does not line up.
ColumnCountMismatch { expected: usize, got: usize },
/// A `NOT NULL` column was given a `NULL` (or omitted) value.
NotNull(String),
/// A value's type does not match the column's declared type.
TypeMismatch { column: String },
/// The parser produced a statement this executor does not run yet.
Unsupported(&'static str),
/// The persisted catalog/row bytes could not be decoded.
Corrupt(&'static str),
}
impl fmt::Display for ExecError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ExecError::Parse(e) => write!(f, "parse error: {e}"),
ExecError::Io(e) => write!(f, "io error: {e}"),
ExecError::TableExists(t) => write!(f, "table already exists: {t}"),
ExecError::NoSuchTable(t) => write!(f, "no such table: {t}"),
ExecError::UnknownColumn(c) => write!(f, "unknown column: {c}"),
ExecError::ColumnCountMismatch { expected, got } => {
write!(f, "column count mismatch: expected {expected}, got {got}")
}
ExecError::NotNull(c) => write!(f, "NOT NULL constraint violated: {c}"),
ExecError::TypeMismatch { column } => write!(f, "type mismatch for column: {column}"),
ExecError::Unsupported(what) => write!(f, "unsupported statement: {what}"),
ExecError::Corrupt(what) => write!(f, "corrupt persisted data: {what}"),
}
}
}
impl std::error::Error for ExecError {}
impl From<io::Error> for ExecError {
fn from(e: io::Error) -> Self {
ExecError::Io(e)
}
}
impl From<SqlError> for ExecError {
fn from(e: SqlError) -> Self {
ExecError::Parse(e)
}
}