Skip to main content

ag_session/execution_graph/
error.rs

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