dataflow_rs/engine/
error.rs1use chrono::Utc;
2use serde::{Deserialize, Serialize};
3use thiserror::Error;
4
5#[derive(Debug, Error, Clone, Serialize, Deserialize)]
7pub enum DataflowError {
8 #[error("Validation error: {0}")]
10 Validation(String),
11
12 #[error("Function execution error: {context}")]
14 FunctionExecution {
15 context: String,
16 #[source]
17 #[serde(skip)]
18 source: Option<Box<DataflowError>>,
19 },
20
21 #[error("Workflow error: {0}")]
23 Workflow(String),
24
25 #[error("Deserialization error: {0}")]
27 Deserialization(String),
28
29 #[error("IO error: {0}")]
31 Io(String),
32
33 #[error("Logic evaluation error: {0}")]
35 LogicEvaluation(String),
36
37 #[error("HTTP error: {status} - {message}")]
39 Http { status: u16, message: String },
40
41 #[error("Timeout error: {0}")]
43 Timeout(String),
44
45 #[error("Unknown error: {0}")]
47 Unknown(String),
48}
49
50impl DataflowError {
51 pub fn function_execution<S: Into<String>>(context: S, source: Option<DataflowError>) -> Self {
53 DataflowError::FunctionExecution {
54 context: context.into(),
55 source: source.map(Box::new),
56 }
57 }
58
59 pub fn http<S: Into<String>>(status: u16, message: S) -> Self {
61 DataflowError::Http {
62 status,
63 message: message.into(),
64 }
65 }
66
67 pub fn from_io(err: std::io::Error) -> Self {
69 DataflowError::Io(err.to_string())
70 }
71
72 pub fn from_serde(err: serde_json::Error) -> Self {
74 DataflowError::Deserialization(err.to_string())
75 }
76}
77
78pub type Result<T> = std::result::Result<T, DataflowError>;
80
81#[derive(Debug, Clone, Serialize, Deserialize)]
83pub struct ErrorInfo {
84 pub workflow_id: Option<String>,
86
87 pub task_id: Option<String>,
89
90 pub timestamp: String,
92
93 pub error_message: String,
95
96 pub retry_attempted: bool,
98
99 pub retry_count: u32,
101}
102
103impl ErrorInfo {
104 pub fn new(workflow_id: Option<String>, task_id: Option<String>, error: DataflowError) -> Self {
106 Self {
107 workflow_id,
108 task_id,
109 timestamp: Utc::now().to_rfc3339(),
110 error_message: error.to_string(),
111 retry_attempted: false,
112 retry_count: 0,
113 }
114 }
115
116 pub fn with_retry(mut self) -> Self {
118 self.retry_attempted = true;
119 self.retry_count += 1;
120 self
121 }
122}