#[non_exhaustive]pub enum QueryError {
Cycle,
TooDeep,
}Expand description
The error returned from Database::get and
System::compute when a query cannot be resolved.
The engine resolves a derived query by running its
compute, which in turn reads other queries. That
recursion terminates only when the dependency graph is acyclic. If a query
asks — directly or through a chain of other queries — for a result that is
itself still being computed, there is no value to return and no way to make
progress: the queries form a cycle. Rather than recurse without bound or
panic, the engine unwinds the whole chain with QueryError::Cycle.
The type is non_exhaustive:
new engine-level failure modes can be added later without breaking a
match that has a wildcard arm.
§Examples
A query that reads itself cannot resolve:
use query_lang::{Database, System, QueryError};
struct SelfReferential;
impl System for SelfReferential {
type Key = u32;
type Value = u32;
fn compute(&self, db: &Database<Self>, key: &u32) -> Result<u32, QueryError> {
// Asking for the very key being computed closes a cycle.
db.get(key)
}
}
let db = Database::new(SelfReferential);
assert_eq!(db.get(&1), Err(QueryError::Cycle));Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Cycle
A query depended on itself, directly or through a chain of other queries.
The dependency graph must be acyclic. When it is not, the query that closed the cycle — and every query waiting on it — resolves to this error. The fix is in the query definitions: break the cyclic dependency, usually by splitting the offending query so the two halves no longer wait on each other.
TooDeep
Resolving a query needed more nested levels than the database allows.
Returned only when a limit was set with
Database::with_max_depth. Each query
that is computing, or revalidating what it read, takes one level. The
usual cause is a long chain of queries that each read the next one.
Trait Implementations§
Source§impl Clone for QueryError
impl Clone for QueryError
impl Copy for QueryError
Source§impl Debug for QueryError
impl Debug for QueryError
Source§impl Display for QueryError
impl Display for QueryError
impl Eq for QueryError
Source§impl Error for QueryError
impl Error for QueryError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()