potato_agent/agents/
error.rs

1use potato_prompt::PromptError;
2use pyo3::exceptions::PyRuntimeError;
3use pyo3::PyErr;
4use thiserror::Error;
5use tracing::error;
6
7#[derive(Error, Debug)]
8pub enum AgentError {
9    #[error("Error: {0}")]
10    Error(String),
11
12    #[error("Failed to downcast Python object: {0}")]
13    DowncastError(String),
14
15    #[error("Failed to get environment variable: {0}")]
16    EnvVarError(#[from] std::env::VarError),
17
18    #[error("Failed to extract client: {0}")]
19    ClientExtractionError(String),
20
21    #[error("No ready tasks found but pending tasks remain. Possible circular dependency.")]
22    NoTaskFoundError,
23
24    #[error("Failed to create runtime: {0}")]
25    CreateRuntimeError(#[source] std::io::Error),
26
27    #[error(transparent)]
28    SerializationError(#[from] serde_json::Error),
29
30    #[error(transparent)]
31    PromptError(#[from] PromptError),
32
33    #[error(transparent)]
34    UtilError(#[from] potato_util::UtilError),
35
36    #[error("Invalid output type: {0}")]
37    InvalidOutputType(String),
38
39    #[error("Failed to create tool: {0}")]
40    ToolCreationError(String),
41
42    #[error("Invalid tool definition")]
43    InvalidToolDefinitionError,
44
45    #[error("{0}")]
46    InvalidInput(String),
47
48    #[error("Provider mismatch: prompt provider {0}, agent provider {1}")]
49    ProviderMismatch(String, String),
50
51    #[error(transparent)]
52    ProviderError(#[from] potato_provider::error::ProviderError),
53
54    #[error("No provider specified in Agent")]
55    MissingProviderError,
56
57    #[error(transparent)]
58    TypeError(#[from] potato_type::TypeError),
59
60    #[error(transparent)]
61    StdIoError(#[from] std::io::Error),
62
63    #[error("Not supported: {0}")]
64    NotSupportedError(String),
65}
66
67impl<'a> From<pyo3::DowncastError<'a, 'a>> for AgentError {
68    fn from(err: pyo3::DowncastError) -> Self {
69        AgentError::DowncastError(err.to_string())
70    }
71}
72
73impl From<AgentError> for PyErr {
74    fn from(err: AgentError) -> PyErr {
75        let msg = err.to_string();
76        error!("{}", msg);
77        PyRuntimeError::new_err(msg)
78    }
79}
80
81impl From<PyErr> for AgentError {
82    fn from(err: PyErr) -> Self {
83        AgentError::Error(err.to_string())
84    }
85}