runtara_workflow_stdlib/runtime/
error.rs1use std::fmt;
6
7#[derive(Debug)]
9pub enum Error {
10 StepFailed(String),
12 InvalidInput(String),
14 AgentError(String),
16 IoError(std::io::Error),
18 JsonError(serde_json::Error),
20 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
71pub type Result<T> = std::result::Result<T, Error>;