use thiserror::Error;
#[derive(Error, Debug)]
pub enum AgentError {
#[error("Session not found: {0}")]
SessionNotFound(String),
#[error("LLM error: {0}")]
LLM(String),
#[error("Empty assistant response from LLM (response_id={response_id:?})")]
EmptyAssistantResponse {
response_id: Option<String>,
},
#[error("LLM overflow: {0}")]
LLMOverflow(String),
#[error("Stream timed out: {0}")]
StreamTimeout(String),
#[error("Tool error: {0}")]
Tool(String),
#[error("Project context error: {0}")]
ProjectContext(String),
#[error("Hook suspended: {0}")]
HookSuspended(String),
#[error("Budget error: {0}")]
Budget(String),
#[error("Cancelled")]
Cancelled,
#[error("Worker unresponsive: {0}")]
WorkerUnresponsive(String),
}
impl AgentError {
pub fn is_cancelled(&self) -> bool {
matches!(self, AgentError::Cancelled)
}
pub fn is_hook_suspended(&self) -> bool {
matches!(self, AgentError::HookSuspended(_))
}
}
#[cfg(test)]
mod tests {
use super::AgentError;
#[test]
fn empty_assistant_response_is_typed_and_has_secret_free_diagnostics() {
let with_id = AgentError::EmptyAssistantResponse {
response_id: Some("resp_740".to_string()),
};
assert!(matches!(
&with_id,
AgentError::EmptyAssistantResponse {
response_id: Some(response_id)
} if response_id == "resp_740"
));
assert_eq!(
with_id.to_string(),
"Empty assistant response from LLM (response_id=Some(\"resp_740\"))"
);
let without_id = AgentError::EmptyAssistantResponse { response_id: None };
assert_eq!(
without_id.to_string(),
"Empty assistant response from LLM (response_id=None)"
);
}
}