Skip to main content

lc_langgraph/
errors.rs

1// crates/lc-langgraph/src/errors.rs
2
3use thiserror::Error;
4
5/// Errors that can occur during graph construction and execution.
6#[derive(Error, Debug)]
7#[non_exhaustive]
8pub enum GraphError {
9    /// A graph validation check failed.
10    #[error("Validation error: {0}")]
11    ValidationError(String),
12
13    /// An error occurred while executing the graph.
14    #[error("Execution error: {0}")]
15    ExecutionError(String),
16
17    /// An error occurred while routing between nodes.
18    #[error("Routing error: {0}")]
19    RoutingError(String),
20
21    /// The recursion limit was reached during execution.
22    #[error("Recursion limit reached: {0}")]
23    RecursionLimitReached(usize),
24
25    /// A node reported an error.
26    #[error("Node error: {0}")]
27    NodeError(String),
28
29    /// A checkpoint operation failed.
30    #[error("Checkpoint error: {0}")]
31    CheckpointError(String),
32
33    /// Optimistic-concurrency conflict while editing a checkpoint
34    /// (`Checkpointer::update_state`): the stored version no longer matches
35    /// the version the caller expected.
36    #[error(
37        "Checkpoint version conflict on '{checkpoint_id}': expected {expected}, found {actual}"
38    )]
39    CheckpointVersionConflict {
40        /// Checkpoint the edit targeted.
41        checkpoint_id: String,
42        /// Version the edit was based on.
43        expected: u64,
44        /// Version currently stored.
45        actual: u64,
46    },
47
48    /// A state update or merge failed.
49    #[error("State error: {0}")]
50    StateError(String),
51
52    /// Execution was interrupted at the named node.
53    #[error("Execution interrupted: {0}")]
54    ExecutionInterrupted(String),
55
56    /// Resuming execution failed.
57    #[error("Resume error: {0}")]
58    ResumeError(String),
59
60    /// The graph contains a cycle with no path to `END`.
61    #[error("Graph contains infinite cycle: {0}")]
62    InfiniteCycleError(String),
63
64    /// A node is unreachable from the entry point.
65    #[error("Orphan node detected: {0}")]
66    OrphanNodeError(String),
67
68    /// Two edges duplicate the same source-target pair.
69    #[error("Duplicate edge: {0}")]
70    DuplicateEdgeError(String),
71
72    /// A routing function returned a key with no matching target.
73    #[error("Missing route target: {0}")]
74    MissingRouteTargetError(String),
75
76    /// An unexpected runtime error occurred.
77    #[error("Runtime error: {0}")]
78    RuntimeError(String),
79}
80
81/// Convenience result type for graph operations.
82pub type GraphResult<T> = Result<T, GraphError>;