Skip to main content

a3s_flow/
error.rs

1//! Error types for a3s-flow.
2
3use thiserror::Error;
4use uuid::Uuid;
5
6/// All errors produced by the flow engine.
7#[derive(Debug, Error)]
8pub enum FlowError {
9    /// The JSON DAG definition is invalid (missing fields, bad structure).
10    #[error("invalid flow definition: {0}")]
11    InvalidDefinition(String),
12
13    /// The DAG contains a cycle, which is forbidden.
14    #[error("flow graph contains a cycle")]
15    CyclicGraph,
16
17    /// A referenced node ID does not exist in the flow definition.
18    #[error("unknown node id: {0}")]
19    UnknownNode(String),
20
21    /// A node execution failed.
22    #[error("node '{node_id}' failed during execution '{execution_id}': {reason}")]
23    NodeFailed {
24        node_id: String,
25        execution_id: Uuid,
26        reason: String,
27    },
28
29    /// The execution was terminated by an external signal.
30    #[error("execution was terminated")]
31    Terminated,
32
33    /// No execution found for the given ID.
34    #[error("execution not found: {0}")]
35    ExecutionNotFound(Uuid),
36
37    /// No flow definition found for the given name in the configured [`FlowStore`](crate::flow_store::FlowStore).
38    #[error("flow not found: {0}")]
39    FlowNotFound(String),
40
41    /// The requested state transition is not valid for the current state.
42    #[error("cannot {action} a {from} execution")]
43    InvalidTransition { action: String, from: String },
44
45    /// JSON serialization / deserialization error.
46    #[error("json error: {0}")]
47    Json(#[from] serde_json::Error),
48
49    /// An unexpected internal error.
50    #[error("internal error: {0}")]
51    Internal(String),
52}
53
54pub type Result<T> = std::result::Result<T, FlowError>;