Skip to main content

wfe_core/models/
execution_error.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
5pub struct ExecutionError {
6    pub error_time: DateTime<Utc>,
7    pub workflow_id: String,
8    pub execution_pointer_id: String,
9    pub message: String,
10}
11
12impl ExecutionError {
13    pub fn new(
14        workflow_id: impl Into<String>,
15        execution_pointer_id: impl Into<String>,
16        message: impl Into<String>,
17    ) -> Self {
18        Self {
19            error_time: Utc::now(),
20            workflow_id: workflow_id.into(),
21            execution_pointer_id: execution_pointer_id.into(),
22            message: message.into(),
23        }
24    }
25}
26
27#[cfg(test)]
28mod tests {
29    use super::*;
30    use pretty_assertions::assert_eq;
31
32    #[test]
33    fn new_error_captures_fields() {
34        let err = ExecutionError::new("wf-1", "ptr-1", "something went wrong");
35        assert_eq!(err.workflow_id, "wf-1");
36        assert_eq!(err.execution_pointer_id, "ptr-1");
37        assert_eq!(err.message, "something went wrong");
38    }
39
40    #[test]
41    fn serde_round_trip() {
42        let err = ExecutionError::new("wf-1", "ptr-1", "fail");
43        let json = serde_json::to_string(&err).unwrap();
44        let deserialized: ExecutionError = serde_json::from_str(&json).unwrap();
45        assert_eq!(err.workflow_id, deserialized.workflow_id);
46        assert_eq!(err.message, deserialized.message);
47    }
48}