Skip to main content

potato_workflow/workflow/
error.rs

1use potato_util::UtilError;
2use pyo3::exceptions::PyRuntimeError;
3use pyo3::PyErr;
4use pythonize::PythonizeError;
5use thiserror::Error;
6use tracing::error;
7
8#[derive(Error, Debug)]
9pub enum WorkflowError {
10    #[error("Error: {0}")]
11    Error(String),
12
13    #[error("Max retries exceeded for task: {0}")]
14    MaxRetriesExceeded(String),
15
16    #[error("Task id already exists: {0}")]
17    TaskAlreadyExists(String),
18
19    #[error("Task dependency not found in registered tasks: {0}")]
20    DependencyNotFound(String),
21
22    #[error("Task not cannot depend on itself: {0}")]
23    TaskDependsOnItself(String),
24
25    #[error(transparent)]
26    UtilError(#[from] UtilError),
27
28    #[error("Failed to create runtime: {0}")]
29    RuntimeError(String),
30
31    #[error("Invalid output type provided for task: {0}")]
32    InvalidOutputType(String),
33
34    #[error(transparent)]
35    SerializationError(#[from] serde_json::Error),
36
37    #[error("Failed to acquire lock on workflow")]
38    LockAcquireError,
39
40    #[error("Failed to acquire read lock on workflow")]
41    ReadLockAcquireError,
42
43    #[error("Failed to acquire write lock on workflow")]
44    WriteLockAcquireError,
45
46    #[error(transparent)]
47    AgentError(#[from] potato_agent::AgentError),
48
49    #[error("Agent not found: {0}")]
50    AgentNotFound(String),
51
52    #[error("Task lock error")]
53    TaskLockError,
54
55    #[error("Task not found: {0}")]
56    TaskNotFound(String),
57
58    #[error("Response validation against JSON schema failed for task: {task_id}. Expected schema: {expected_schema}, Received response: {received_response}")]
59    ResponseValidationFailed {
60        task_id: String,
61        expected_schema: String,
62        received_response: String,
63    },
64}
65impl From<PythonizeError> for WorkflowError {
66    fn from(err: PythonizeError) -> Self {
67        WorkflowError::Error(err.to_string())
68    }
69}
70
71impl From<WorkflowError> for PyErr {
72    fn from(err: WorkflowError) -> PyErr {
73        let msg = err.to_string();
74        error!("{}", msg);
75        PyRuntimeError::new_err(msg)
76    }
77}
78
79impl From<PyErr> for WorkflowError {
80    fn from(err: PyErr) -> Self {
81        WorkflowError::Error(err.to_string())
82    }
83}