adk_graph/
error.rs

1//! Error types for adk-graph
2
3use crate::interrupt::Interrupt;
4use thiserror::Error;
5
6/// Result type for graph operations
7pub type Result<T> = std::result::Result<T, GraphError>;
8
9/// Errors that can occur during graph operations
10#[derive(Error, Debug)]
11pub enum GraphError {
12    /// Graph structure is invalid
13    #[error("Invalid graph structure: {0}")]
14    InvalidGraph(String),
15
16    /// Node not found
17    #[error("Node not found: {0}")]
18    NodeNotFound(String),
19
20    /// Edge target not found
21    #[error("Edge target not found: {0}")]
22    EdgeTargetNotFound(String),
23
24    /// No entry point defined
25    #[error("No entry point defined (missing edge from START)")]
26    NoEntryPoint,
27
28    /// Recursion limit exceeded
29    #[error("Recursion limit exceeded: {0} steps")]
30    RecursionLimitExceeded(usize),
31
32    /// Execution was interrupted
33    #[error("Execution interrupted: {0:?}")]
34    Interrupted(Box<InterruptedExecution>),
35
36    /// Node execution failed
37    #[error("Node '{node}' execution failed: {message}")]
38    NodeExecutionFailed { node: String, message: String },
39
40    /// State serialization error
41    #[error("State serialization error: {0}")]
42    SerializationError(String),
43
44    /// Checkpoint error
45    #[error("Checkpoint error: {0}")]
46    CheckpointError(String),
47
48    /// Router returned unknown target
49    #[error("Router returned unknown target: {0}")]
50    UnknownRouteTarget(String),
51
52    /// ADK core error
53    #[error("ADK error: {0}")]
54    AdkError(#[from] adk_core::AdkError),
55
56    /// IO error
57    #[error("IO error: {0}")]
58    IoError(#[from] std::io::Error),
59
60    /// JSON error
61    #[error("JSON error: {0}")]
62    JsonError(#[from] serde_json::Error),
63
64    /// Database error (when sqlite feature enabled)
65    #[cfg(feature = "sqlite")]
66    #[error("Database error: {0}")]
67    DatabaseError(#[from] sqlx::Error),
68}
69
70/// Information about an interrupted execution
71#[derive(Debug, Clone)]
72pub struct InterruptedExecution {
73    /// Thread ID for resumption
74    pub thread_id: String,
75    /// Checkpoint ID for resumption
76    pub checkpoint_id: String,
77    /// The interrupt that occurred
78    pub interrupt: Interrupt,
79    /// Current state at interruption
80    pub state: crate::state::State,
81    /// Step number when interrupted
82    pub step: usize,
83}
84
85impl InterruptedExecution {
86    /// Create a new interrupted execution
87    pub fn new(
88        thread_id: String,
89        checkpoint_id: String,
90        interrupt: Interrupt,
91        state: crate::state::State,
92        step: usize,
93    ) -> Self {
94        Self { thread_id, checkpoint_id, interrupt, state, step }
95    }
96}