Menu
Public repository / ee7487eee78cd52cdafdcb22b6ff4bf57093d6e9
AkurAI-Framework / crates/sql/src/error.rs
Latest change 5a1781679346dc042a413c85c2ddfc034f219ae0 - feat(sql): lexer + parser for a SQL subset (AST) by Ólafur Búi Ólafsson
//! SQL lex/parse errors, with the character offset where they occurred.
use std::fmt;
/// A SQL failure: a human-readable message plus the 0-based character position
/// in the input where lexing or parsing gave up. Malformed input always yields
/// one of these — never a panic.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SqlError {
pub message: String,
pub position: usize,
}
impl SqlError {
pub(crate) fn new(message: impl Into<String>, position: usize) -> SqlError {
SqlError {
message: message.into(),
position,
}
}
}
impl fmt::Display for SqlError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{} at position {}", self.message, self.position)
}
}
impl std::error::Error for SqlError {}