rustledger_query/
error.rs

1//! BQL error types.
2
3use thiserror::Error;
4
5/// Error returned when parsing a BQL query fails.
6#[derive(Debug, Error)]
7#[error("parse error at position {position}: {kind}")]
8pub struct ParseError {
9    /// The kind of error.
10    pub kind: ParseErrorKind,
11    /// Position in the input where the error occurred.
12    pub position: usize,
13}
14
15/// The kind of parse error.
16#[derive(Debug, Error)]
17pub enum ParseErrorKind {
18    /// Unexpected end of input.
19    #[error("unexpected end of input")]
20    UnexpectedEof,
21    /// Syntax error with details.
22    #[error("{0}")]
23    SyntaxError(String),
24}
25
26impl ParseError {
27    /// Create a new parse error.
28    pub const fn new(kind: ParseErrorKind, position: usize) -> Self {
29        Self { kind, position }
30    }
31}
32
33/// Error returned when executing a query fails.
34#[derive(Debug, Error)]
35pub enum QueryError {
36    /// Parse error.
37    #[error("parse error: {0}")]
38    Parse(#[from] ParseError),
39    /// Type error (incompatible types in operation).
40    #[error("type error: {0}")]
41    Type(String),
42    /// Unknown column name.
43    #[error("unknown column: {0}")]
44    UnknownColumn(String),
45    /// Unknown function name.
46    #[error("unknown function: {0}")]
47    UnknownFunction(String),
48    /// Invalid function arguments.
49    #[error("invalid arguments for function {0}: {1}")]
50    InvalidArguments(String, String),
51    /// Aggregation error.
52    #[error("aggregation error: {0}")]
53    Aggregation(String),
54    /// Evaluation error.
55    #[error("evaluation error: {0}")]
56    Evaluation(String),
57}