Skip to main content

ag_session/execution_graph/
error.rs

1/// A structural graph or exact-result binding violation.
2#[derive(Clone, Debug, Eq, PartialEq, thiserror::Error)]
3pub enum GraphContractError {
4    /// A required identity or name is blank.
5    #[error("graph field `{0}` must not be blank")]
6    EmptyField(&'static str),
7    /// A graph must contain at least one node.
8    #[error("graph must contain at least one node")]
9    EmptyGraph,
10    /// A scoped identity, dependency, or name occurs more than once.
11    #[error("duplicate graph {kind}: {id}")]
12    Duplicate {
13        /// Identity scope that requires uniqueness.
14        kind: &'static str,
15        /// Conflicting value.
16        id: String,
17    },
18    /// An edge or input references a missing node.
19    #[error("unknown graph node: {0}")]
20    UnknownNode(String),
21    /// A gate or binding references an undeclared output.
22    #[error("unknown output `{output}` of graph node `{node}`")]
23    UnknownOutput {
24        /// Producing node.
25        node: String,
26        /// Missing output name.
27        output: String,
28    },
29    /// A dependency cycle, including a self-dependency, exists.
30    #[error("graph dependencies contain a cycle")]
31    Cycle,
32    /// An input lacks a validation or acceptance gate for its exact output.
33    #[error("input `{0}` requires a dependency gate for its producing output")]
34    UngatedInput(String),
35    /// The execution contract combines incompatible requirements.
36    #[error("invalid graph execution profile: {0}")]
37    InvalidProfile(&'static str),
38    /// An execution environment is not owned by the graph's session.
39    #[error("graph node environment belongs to a different session")]
40    ForeignEnv,
41    /// A runtime result does not match the declared input and producer.
42    #[error("graph result does not match {0}")]
43    ResultMismatch(&'static str),
44    /// A result has not reached the binding's declared gate.
45    #[error("graph result has not satisfied the input gate")]
46    UnsatisfiedGate,
47}
48
49impl GraphContractError {
50    /// Checks a required string without normalizing its durable identity.
51    pub(super) fn require(value: &str, field: &'static str) -> Result<(), Self> {
52        if value.trim().is_empty() {
53            return Err(Self::EmptyField(field));
54        }
55
56        Ok(())
57    }
58}