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    /// A descriptor the planner depends on is being drained by
31    /// an in-flight DDL. Callers (pgwire handlers) should retry
32    /// the whole statement after a short backoff. Propagated
33    /// from `SqlCatalogError::RetryableSchemaChanged`.
34    #[error("retryable schema change on {descriptor}")]
35    RetryableSchemaChanged { descriptor: String },
36}
37
38impl From<crate::catalog::SqlCatalogError> for SqlError {
39    fn from(e: crate::catalog::SqlCatalogError) -> Self {
40        match e {
41            crate::catalog::SqlCatalogError::RetryableSchemaChanged { descriptor } => {
42                Self::RetryableSchemaChanged { descriptor }
43            }
44        }
45    }
46}
47
48impl From<sqlparser::parser::ParserError> for SqlError {
49    fn from(e: sqlparser::parser::ParserError) -> Self {
50        Self::Parse {
51            detail: e.to_string(),
52        }
53    }
54}
55
56pub type Result<T> = std::result::Result<T, SqlError>;