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    /// A state update or merge failed.
34    #[error("State error: {0}")]
35    StateError(String),
36
37    /// Execution was interrupted at the named node.
38    #[error("Execution interrupted: {0}")]
39    ExecutionInterrupted(String),
40
41    /// Resuming execution failed.
42    #[error("Resume error: {0}")]
43    ResumeError(String),
44
45    /// The graph contains a cycle with no path to `END`.
46    #[error("Graph contains infinite cycle: {0}")]
47    InfiniteCycleError(String),
48
49    /// A node is unreachable from the entry point.
50    #[error("Orphan node detected: {0}")]
51    OrphanNodeError(String),
52
53    /// Two edges duplicate the same source-target pair.
54    #[error("Duplicate edge: {0}")]
55    DuplicateEdgeError(String),
56
57    /// A routing function returned a key with no matching target.
58    #[error("Missing route target: {0}")]
59    MissingRouteTargetError(String),
60
61    /// An unexpected runtime error occurred.
62    #[error("Runtime error: {0}")]
63    RuntimeError(String),
64}
65
66/// Convenience result type for graph operations.
67pub type GraphResult<T> = Result<T, GraphError>;