ankql/
error.rs

1use crate::grammar;
2use std::convert::Infallible;
3use thiserror::Error;
4
5#[cfg(feature = "wasm")]
6use wasm_bindgen;
7
8/// Custom error type for parsing errors
9#[derive(Debug, Error)]
10pub enum ParseError {
11    #[error("Syntax error: {0}")]
12    SyntaxError(String),
13    #[error("Empty expression")]
14    EmptyExpression,
15    #[error("Expected {expected}, got {got:?}")]
16    UnexpectedRule { expected: &'static str, got: grammar::Rule },
17    #[error("Invalid predicate: {0}")]
18    InvalidPredicate(String),
19    #[error("Missing {0} operand")]
20    MissingOperand(&'static str),
21}
22
23impl From<Infallible> for ParseError {
24    fn from(_: Infallible) -> Self { unreachable!("Infallible can never be constructed") }
25}
26
27#[cfg(feature = "wasm")]
28impl From<ParseError> for wasm_bindgen::JsValue {
29    fn from(error: ParseError) -> Self { wasm_bindgen::JsValue::from_str(&error.to_string()) }
30}
31
32/// Custom error type for SQL generation errors
33#[derive(Debug, Error)]
34pub enum SqlGenerationError {
35    #[error("Placeholder count mismatch: expected {expected}, found {found}")]
36    PlaceholderCountMismatch { expected: usize, found: usize },
37    #[error("Invalid expression: {0}")]
38    InvalidExpression(String),
39    #[error("Unsupported operator: {0}")]
40    UnsupportedOperator(&'static str),
41}