Skip to main content

marsdb_query/
error.rs

1/// Typed error taxonomy, in three tiers that reflect *when* the problem
2/// was knowable:
3///
4/// - [`Syntax`](QueryError::Syntax): the query text itself is malformed —
5///   never reached planning/execution at all (`parser.rs`, including
6///   `pest`'s own grammar failures).
7/// - [`Semantic`](QueryError::Semantic): the query text parsed fine but
8///   describes something structurally invalid — knowable from the query
9///   alone, no data/parameters needed (an unsupported pattern shape, an
10///   aggregate nested somewhere it can't be, `EXPLAIN EXPLAIN`, ...).
11/// - [`Type`](QueryError::Type): only knowable once a real value (from
12///   stored data or a `$parameter`) is in hand and turns out to be the
13///   wrong shape (arithmetic on a non-number, indexing a non-list, a
14///   `date({...})` field of the wrong type, ...).
15///
16/// Callers that only need "did it work" (most of this codebase) keep
17/// using `Display`/`?` as before — this tiering exists for callers that
18/// want to react differently to "you wrote something illegal" vs "the
19/// data didn't match what the query assumed" (an application surfacing
20/// user-facing messages, or `ExecutionOutcome`'s telemetry categories).
21#[derive(Debug, thiserror::Error)]
22pub enum QueryError {
23    #[error("syntax error: {0}")]
24    Syntax(String),
25    #[error("semantic error: {0}")]
26    Semantic(String),
27    #[error("type error: {0}")]
28    Type(String),
29    #[error("graph error: {0}")]
30    Graph(#[from] marsdb_graph::GraphError),
31    #[error("unbound variable: {0}")]
32    UnboundVariable(String),
33    #[error("missing value for parameter: ${0}")]
34    MissingParam(String),
35    #[error("query cancelled")]
36    Cancelled,
37    #[error("query timed out")]
38    Timeout,
39    #[error("query resource limit exceeded: {0}")]
40    ResourceLimit(String),
41}