Skip to main content

juncture_core/node/
mod.rs

1//! Node system for graph execution
2//!
3//! This module provides the [`Node`] trait and conversion utilities for creating
4//! nodes from async functions. Nodes are the basic unit of execution in a Juncture graph.
5
6mod into_node;
7mod r#trait;
8
9pub use into_node::{
10    IntoNode, NodeFnCommand, NodeFnCommandWithConfig, NodeFnCommandWithConfigAndRuntime,
11    NodeFnCommandWithRuntime, NodeFnUpdate, NodeFnUpdateWithConfig,
12    NodeFnUpdateWithConfigAndRuntime, NodeFnUpdateWithRuntime,
13};
14pub use r#trait::Node;
15
16/// Error information for node execution failures
17///
18/// Contains details about which node failed, the error that occurred,
19/// the state at time of failure, and the attempt count.
20#[derive(Debug)]
21pub struct NodeError<S: crate::State> {
22    /// Name of the node that failed
23    pub node: String,
24
25    /// The error that caused the failure
26    pub error: crate::JunctureError,
27
28    /// State snapshot at time of failure
29    pub state: S,
30
31    /// Current attempt count (1-indexed)
32    pub attempt: u32,
33}
34
35impl<S: crate::State> std::fmt::Display for NodeError<S> {
36    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37        write!(
38            f,
39            "Node '{}' failed on attempt {}: {}",
40            self.node, self.attempt, self.error
41        )
42    }
43}
44
45impl<S: crate::State> std::error::Error for NodeError<S> {
46    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
47        self.error.source()
48    }
49}
50
51// Rust guideline compliant 2025-01-18