Skip to main content

nodedb_sql/
error.rs

1//! Error types for the nodedb-sql crate.
2
3/// Errors produced during SQL parsing, resolution, or planning.
4#[derive(Debug, thiserror::Error)]
5pub enum SqlError {
6    #[error("parse error: {detail}")]
7    Parse { detail: String },
8
9    #[error("unknown table: {name}")]
10    UnknownTable { name: String },
11
12    #[error("unknown column '{column}' in table '{table}'")]
13    UnknownColumn { table: String, column: String },
14
15    #[error("ambiguous column '{column}' — qualify with table name")]
16    AmbiguousColumn { column: String },
17
18    #[error("type mismatch: {detail}")]
19    TypeMismatch { detail: String },
20
21    #[error("unsupported: {detail}")]
22    Unsupported { detail: String },
23
24    #[error("invalid function call: {detail}")]
25    InvalidFunction { detail: String },
26
27    #[error("missing required field '{field}' for {context}")]
28    MissingField { field: String, context: String },
29}
30
31impl From<sqlparser::parser::ParserError> for SqlError {
32    fn from(e: sqlparser::parser::ParserError) -> Self {
33        Self::Parse {
34            detail: e.to_string(),
35        }
36    }
37}
38
39pub type Result<T> = std::result::Result<T, SqlError>;