Skip to main content

crates_docs/error/
mod.rs

1//! Error handling module
2
3use thiserror::Error;
4
5/// Application error types
6#[derive(Error, Debug)]
7pub enum Error {
8    /// Initialization error
9    #[error("Initialization failed: {0}")]
10    Initialization(String),
11
12    /// Configuration error
13    #[error("Configuration error: {0}")]
14    Config(String),
15
16    /// HTTP request error
17    #[error("HTTP request failed: {0}")]
18    HttpRequest(String),
19
20    /// Parse error
21    #[error("Parse failed: {0}")]
22    Parse(String),
23
24    /// Cache error
25    #[error("Cache operation failed: {0}")]
26    Cache(String),
27
28    /// Authentication error
29    #[error("Authentication failed: {0}")]
30    Auth(String),
31
32    /// MCP protocol error
33    #[error("MCP protocol error: {0}")]
34    Mcp(String),
35
36    /// IO error
37    #[error("IO error: {0}")]
38    Io(#[from] std::io::Error),
39
40    /// JSON serialization/deserialization error
41    #[error("JSON error: {0}")]
42    Json(#[from] serde_json::Error),
43
44    /// URL parse error
45    #[error("URL parse error: {0}")]
46    Url(#[from] url::ParseError),
47
48    /// Reqwest error
49    #[error("HTTP client error: {0}")]
50    Reqwest(#[from] reqwest::Error),
51
52    /// Other error
53    #[error("Unknown error: {0}")]
54    Other(String),
55}
56
57/// Result type alias
58pub type Result<T> = std::result::Result<T, Error>;
59
60impl From<Box<dyn std::error::Error + Send + Sync>> for Error {
61    fn from(err: Box<dyn std::error::Error + Send + Sync>) -> Self {
62        Error::Other(err.to_string())
63    }
64}
65
66impl From<anyhow::Error> for Error {
67    fn from(err: anyhow::Error) -> Self {
68        Error::Other(err.to_string())
69    }
70}