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)]
5/// Executionerror.
6pub struct ExecutionError {
7    /// Error time.
8    pub error_time: DateTime<Utc>,
9    /// Workflow id.
10    pub workflow_id: String,
11    /// Execution pointer id.
12    pub execution_pointer_id: String,
13    /// Message.
14    pub message: String,
15}
16
17impl ExecutionError {
18    pub fn new(
19        workflow_id: impl Into<String>,
20        execution_pointer_id: impl Into<String>,
21        message: impl Into<String>,
22    ) -> Self {
23        Self {
24            error_time: Utc::now(),
25            workflow_id: workflow_id.into(),
26            execution_pointer_id: execution_pointer_id.into(),
27            message: message.into(),
28        }
29    }
30}
31
32#[cfg(test)]
33mod tests {
34    use super::*;
35    use pretty_assertions::assert_eq;
36
37    #[test]
38    fn new_error_captures_fields() {
39        let err = ExecutionError::new("wf-1", "ptr-1", "something went wrong");
40        assert_eq!(err.workflow_id, "wf-1");
41        assert_eq!(err.execution_pointer_id, "ptr-1");
42        assert_eq!(err.message, "something went wrong");
43    }
44
45    #[test]
46    fn serde_round_trip() {
47        let err = ExecutionError::new("wf-1", "ptr-1", "fail");
48        let json = serde_json::to_string(&err).unwrap();
49        let deserialized: ExecutionError = serde_json::from_str(&json).unwrap();
50        assert_eq!(err.workflow_id, deserialized.workflow_id);
51        assert_eq!(err.message, deserialized.message);
52    }
53}