Skip to main content

ironflow_engine/
error.rs

1//! Engine error types.
2
3use thiserror::Error;
4
5use ironflow_core::error::OperationError;
6use ironflow_store::error::StoreError;
7
8/// Errors produced by the workflow engine.
9#[derive(Debug, Error)]
10pub enum EngineError {
11    /// An operation (Shell, Http, Agent) failed during step execution.
12    #[error("operation failed: {0}")]
13    Operation(#[from] OperationError),
14
15    /// The backing store returned an error.
16    #[error("store error: {0}")]
17    Store(#[from] StoreError),
18
19    /// The workflow definition is invalid.
20    #[error("invalid workflow: {0}")]
21    InvalidWorkflow(String),
22
23    /// A step configuration could not be deserialized for execution.
24    #[error("step config error: {0}")]
25    StepConfig(String),
26
27    /// JSON serialization error.
28    #[error("serialization error: {0}")]
29    Serialization(#[from] serde_json::Error),
30
31    /// The run requires human approval before continuing.
32    #[error("approval required for run {run_id}, step {step_id}: {message}")]
33    ApprovalRequired {
34        /// The run that is awaiting approval.
35        run_id: uuid::Uuid,
36        /// The approval step that triggered the pause.
37        step_id: uuid::Uuid,
38        /// The approval message.
39        message: String,
40    },
41}
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn invalid_workflow_display() {
49        let err = EngineError::InvalidWorkflow("unknown-handler".to_string());
50        assert!(err.to_string().contains("invalid workflow"));
51        assert!(err.to_string().contains("unknown-handler"));
52    }
53
54    #[test]
55    fn step_config_display() {
56        let err = EngineError::StepConfig("bad shell config".to_string());
57        assert!(err.to_string().contains("step config error"));
58        assert!(err.to_string().contains("bad shell config"));
59    }
60
61    #[test]
62    fn store_error_from_conversion() {
63        let store_err = StoreError::RunNotFound(uuid::Uuid::nil());
64        let engine_err = EngineError::from(store_err);
65        assert!(engine_err.to_string().contains("store error"));
66    }
67
68    #[test]
69    fn serialization_error_from_conversion() {
70        let serde_err = serde_json::from_str::<String>("not json").unwrap_err();
71        let engine_err = EngineError::from(serde_err);
72        assert!(engine_err.to_string().contains("serialization error"));
73    }
74}