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    /// An expansion must append at least one node.
13    #[error("graph expansion must append at least one node")]
14    EmptyExpansion,
15    /// The graph has no revision number left for another revision.
16    #[error("graph revision counter is exhausted")]
17    RevisionExhausted,
18    /// A scoped identity, dependency, or name occurs more than once.
19    #[error("duplicate graph {kind}: {id}")]
20    Duplicate {
21        /// Identity scope that requires uniqueness.
22        kind: &'static str,
23        /// Conflicting value.
24        id: String,
25    },
26    /// An edge or input references a missing node.
27    #[error("unknown graph node: {0}")]
28    UnknownNode(String),
29    /// A gate or binding references an undeclared output.
30    #[error("unknown output `{output}` of graph node `{node}`")]
31    UnknownOutput {
32        /// Producing node.
33        node: String,
34        /// Missing output name.
35        output: String,
36    },
37    /// A dependency cycle, including a self-dependency, exists.
38    #[error("graph dependencies contain a cycle")]
39    Cycle,
40    /// An input lacks a validation or acceptance gate for its exact output.
41    #[error("input `{0}` requires a dependency gate for its producing output")]
42    UngatedInput(String),
43    /// The execution contract combines incompatible requirements.
44    #[error("invalid graph execution profile: {0}")]
45    InvalidProfile(&'static str),
46    /// An execution environment is not owned by the graph's session.
47    #[error("graph node environment belongs to a different session")]
48    ForeignEnv,
49    /// A node references a task worktree, which graphs cannot dispatch yet.
50    #[error("graph nodes cannot run in task worktrees yet")]
51    UnsupportedEnv,
52    /// A runtime result does not match the declared input and producer.
53    #[error("graph result does not match {0}")]
54    ResultMismatch(&'static str),
55    /// A result has not reached the binding's declared gate.
56    #[error("graph result has not satisfied the input gate")]
57    UnsatisfiedGate,
58}
59
60impl GraphContractError {
61    /// Checks a required string without normalizing its durable identity.
62    pub(super) fn require(value: &str, field: &'static str) -> Result<(), Self> {
63        if value.trim().is_empty() {
64            return Err(Self::EmptyField(field));
65        }
66
67        Ok(())
68    }
69}