runtara_workflow_stdlib/runtime/
error.rs

1// Copyright (C) 2025 SyncMyOrders Sp. z o.o.
2// SPDX-License-Identifier: AGPL-3.0-or-later
3//! Error types for workflow execution
4
5use std::fmt;
6
7/// Error type for workflow execution
8#[derive(Debug)]
9pub enum Error {
10    /// Step execution failed
11    StepFailed(String),
12    /// Invalid input
13    InvalidInput(String),
14    /// Agent error
15    AgentError(String),
16    /// IO error
17    IoError(std::io::Error),
18    /// JSON error
19    JsonError(serde_json::Error),
20    /// Other error
21    Other(String),
22}
23
24impl fmt::Display for Error {
25    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26        match self {
27            Error::StepFailed(msg) => write!(f, "Step failed: {}", msg),
28            Error::InvalidInput(msg) => write!(f, "Invalid input: {}", msg),
29            Error::AgentError(msg) => write!(f, "Agent error: {}", msg),
30            Error::IoError(e) => write!(f, "IO error: {}", e),
31            Error::JsonError(e) => write!(f, "JSON error: {}", e),
32            Error::Other(msg) => write!(f, "{}", msg),
33        }
34    }
35}
36
37impl std::error::Error for Error {
38    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
39        match self {
40            Error::IoError(e) => Some(e),
41            Error::JsonError(e) => Some(e),
42            _ => None,
43        }
44    }
45}
46
47impl From<std::io::Error> for Error {
48    fn from(e: std::io::Error) -> Self {
49        Error::IoError(e)
50    }
51}
52
53impl From<serde_json::Error> for Error {
54    fn from(e: serde_json::Error) -> Self {
55        Error::JsonError(e)
56    }
57}
58
59impl From<String> for Error {
60    fn from(s: String) -> Self {
61        Error::Other(s)
62    }
63}
64
65impl From<&str> for Error {
66    fn from(s: &str) -> Self {
67        Error::Other(s.to_string())
68    }
69}
70
71/// Result type for workflow execution
72pub type Result<T> = std::result::Result<T, Error>;