Skip to main content

qualia_core_db/q42/chebi_query/
error.rs

1//! Fail-closed errors for ChEBI in-memory queries (AST-05).
2
3use std::fmt;
4
5/// Typed query failures — empty / ambiguous / limit paths never succeed quietly.
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub enum QueryError {
8    /// Caller supplied an empty Quin slice where at least one Quin is required.
9    EmptyInput,
10    /// Query string was empty or could not be normalized to an accession.
11    EmptyQuery,
12    /// No compound matched the query in the supplied slice.
13    NotFound,
14    /// More than one distinct compound matched a unique-style resolve.
15    Ambiguous { hits: usize },
16    /// Result count would exceed the caller limit / output capacity.
17    LimitExceeded { limit: usize, needed: usize },
18    /// Output buffer filled before the walk/export completed.
19    OutputFull { written: usize, capacity: usize },
20    /// [`super::QueryLimits`] fields must be strictly positive.
21    InvalidLimits,
22    /// Subgraph walk stopped because depth would exceed the ceiling.
23    DepthExceeded { depth: usize, max: usize },
24}
25
26impl fmt::Display for QueryError {
27    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28        match self {
29            Self::EmptyInput => write!(f, "empty quin input"),
30            Self::EmptyQuery => write!(f, "empty or unnormalizable chemical query"),
31            Self::NotFound => write!(f, "chemical not found in asset slice"),
32            Self::Ambiguous { hits } => write!(f, "ambiguous chemical match (hits={hits})"),
33            Self::LimitExceeded { limit, needed } => {
34                write!(f, "query limit exceeded (limit={limit}, needed={needed})")
35            }
36            Self::OutputFull { written, capacity } => {
37                write!(f, "output full (written={written}, capacity={capacity})")
38            }
39            Self::InvalidLimits => write!(f, "query limits must be positive"),
40            Self::DepthExceeded { depth, max } => {
41                write!(f, "subgraph depth exceeded (depth={depth}, max={max})")
42            }
43        }
44    }
45}
46
47impl std::error::Error for QueryError {}