query_flow/error.rs
1//! Error types for query execution.
2
3use std::fmt;
4
5/// System-level query errors.
6///
7/// These are distinct from user domain errors, which should be wrapped
8/// in `Query::Output` (e.g., `type Output = Result<T, MyError>`).
9#[derive(Debug, Clone)]
10pub enum QueryError {
11 /// Query is waiting for async loading to complete.
12 ///
13 /// This is returned when a dependency is still loading via a background task.
14 /// Use `runtime.query_async()` to wait for loading to complete, or handle
15 /// explicitly in your query logic.
16 Suspend,
17
18 /// Dependency cycle detected.
19 ///
20 /// The query graph contains a cycle, which would cause infinite recursion.
21 /// The `path` contains a debug representation of the cycle.
22 Cycle {
23 /// Debug representation of the queries forming the cycle.
24 path: Vec<String>,
25 },
26
27 /// Query execution was cancelled.
28 Cancelled,
29
30 /// A required dependency is missing.
31 MissingDependency {
32 /// Description of the missing dependency.
33 description: String,
34 },
35}
36
37impl fmt::Display for QueryError {
38 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39 match self {
40 QueryError::Suspend => write!(f, "query suspended: waiting for async loading"),
41 QueryError::Cycle { path } => {
42 write!(f, "dependency cycle detected: {}", path.join(" -> "))
43 }
44 QueryError::Cancelled => write!(f, "query cancelled"),
45 QueryError::MissingDependency { description } => {
46 write!(f, "missing dependency: {}", description)
47 }
48 }
49 }
50}
51
52impl std::error::Error for QueryError {}