1use std::fmt::Display;
2use thiserror::Error;
3
4#[derive(Error, Debug, Clone)]
6pub enum FloxideError {
7 #[error("Node execution error: {0}")]
9 NodeExecution(String),
10
11 #[error("Workflow execution error: {0}")]
13 WorkflowExecution(String),
14
15 #[error("Node not found: {0}")]
17 NodeNotFound(String),
18
19 #[error("No transition defined for action: {0}")]
21 NoTransitionDefined(String),
22
23 #[error("Serialization error: {0}")]
25 SerializationError(String),
26
27 #[error("Deserialization error: {0}")]
29 DeserializationError(String),
30
31 #[error("Task join error: {0}")]
33 JoinError(String),
34
35 #[error("Cycle detected in workflow execution")]
37 WorkflowCycleDetected,
38
39 #[error("Workflow definition error: {0}")]
41 WorkflowDefinitionError(String),
42
43 #[error("Batch processing error: {0}")]
45 BatchProcessingError(String),
46
47 #[error("Unexpected node outcome: {0}")]
49 UnexpectedOutcome(String),
50
51 #[error("{0}")]
53 Other(String),
54}
55
56pub type FloxideResult<T> = Result<T, FloxideError>;
58
59impl FloxideError {
60 pub fn node_execution(node_id: impl Display, message: impl Display) -> Self {
62 Self::NodeExecution(format!("Node {}: {}", node_id, message))
63 }
64
65 pub fn batch_processing(
67 message: impl Display,
68 source: Box<dyn std::error::Error + Send + Sync>,
69 ) -> Self {
70 Self::BatchProcessingError(format!("{}: {}", message, source))
71 }
72
73 pub fn unexpected_outcome(message: impl Display) -> Self {
75 Self::UnexpectedOutcome(message.to_string())
76 }
77
78 pub fn node_not_found(node_id: impl Display) -> Self {
80 Self::NodeNotFound(node_id.to_string())
81 }
82
83 pub fn timeout(message: impl Display) -> Self {
85 Self::Other(format!("Timeout: {}", message))
86 }
87
88 pub fn is_timeout(&self) -> bool {
90 match self {
91 Self::Other(msg) => msg.starts_with("Timeout:"),
92 _ => false,
93 }
94 }
95}