Skip to main content

agent_diva_nano/
error.rs

1use std::fmt;
2
3/// Errors that can occur when using the nano agent library.
4#[derive(Debug)]
5pub enum NanoError {
6    /// The agent failed to process the request.
7    Agent(String),
8    /// A provider (LLM) error occurred.
9    Provider(String),
10    /// The request timed out.
11    Timeout,
12    /// An I/O or configuration error.
13    Other(String),
14}
15
16impl fmt::Display for NanoError {
17    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18        match self {
19            NanoError::Agent(msg) => write!(f, "agent error: {msg}"),
20            NanoError::Provider(msg) => write!(f, "provider error: {msg}"),
21            NanoError::Timeout => write!(f, "request timed out"),
22            NanoError::Other(msg) => write!(f, "{msg}"),
23        }
24    }
25}
26
27impl std::error::Error for NanoError {}
28
29impl From<anyhow::Error> for NanoError {
30    fn from(err: anyhow::Error) -> Self {
31        NanoError::Other(err.to_string())
32    }
33}