Skip to main content

agent_diva_core/
error.rs

1//! Error types for agent-diva
2
3use thiserror::Error;
4
5/// The main error type for agent-diva operations
6#[derive(Error, Debug)]
7pub enum Error {
8    /// Configuration errors
9    #[error("Configuration error: {0}")]
10    Config(String),
11
12    /// I/O errors
13    #[error("I/O error: {0}")]
14    Io(#[from] std::io::Error),
15
16    /// Serialization errors
17    #[error("Serialization error: {0}")]
18    Serialization(String),
19
20    /// Session management errors
21    #[error("Session error: {0}")]
22    Session(String),
23
24    /// Channel communication errors
25    #[error("Channel error: {0}")]
26    Channel(String),
27
28    /// Provider (LLM) errors
29    #[error("Provider error: {0}")]
30    Provider(String),
31
32    /// Tool execution errors
33    #[error("Tool error: {0}")]
34    Tool(String),
35
36    /// Validation errors
37    #[error("Validation error: {0}")]
38    Validation(String),
39
40    /// Not found errors
41    #[error("Not found: {0}")]
42    NotFound(String),
43
44    /// Unauthorized access
45    #[error("Unauthorized: {0}")]
46    Unauthorized(String),
47
48    /// Internal errors
49    #[error("Internal error: {0}")]
50    Internal(String),
51}
52
53/// A specialized Result type for agent-diva operations
54pub type Result<T> = std::result::Result<T, Error>;
55
56impl From<serde_json::Error> for Error {
57    fn from(e: serde_json::Error) -> Self {
58        Error::Serialization(e.to_string())
59    }
60}
61
62impl From<config::ConfigError> for Error {
63    fn from(e: config::ConfigError) -> Self {
64        Error::Config(e.to_string())
65    }
66}