agentic_connect/types/
error.rs1use thiserror::Error;
4
5#[derive(Debug, Error)]
7pub enum ConnectError {
8 #[error("Connection failed: {0}")]
9 ConnectionFailed(String),
10
11 #[error("Authentication failed: {0}")]
12 AuthFailed(String),
13
14 #[error("Protocol error: {0}")]
15 ProtocolError(String),
16
17 #[error("Timeout after {0}ms")]
18 Timeout(u64),
19
20 #[error("Rate limited: retry after {retry_after_secs}s")]
21 RateLimited { retry_after_secs: u64 },
22
23 #[error("Circuit breaker open for {endpoint}")]
24 CircuitOpen { endpoint: String },
25
26 #[error("Credential not found: {0}")]
27 CredentialNotFound(String),
28
29 #[error("Encryption error: {0}")]
30 EncryptionError(String),
31
32 #[error("Invalid configuration: {0}")]
33 InvalidConfig(String),
34
35 #[error("Not supported: {0}")]
36 NotSupported(String),
37
38 #[error("IO error: {0}")]
39 Io(#[from] std::io::Error),
40
41 #[error("HTTP error: {0}")]
42 Http(String),
43
44 #[error("Database error: {0}")]
45 Database(String),
46
47 #[error("Serialization error: {0}")]
48 Serialization(String),
49}
50
51pub type ConnectResult<T> = Result<T, ConnectError>;
53
54impl From<serde_json::Error> for ConnectError {
55 fn from(e: serde_json::Error) -> Self {
56 ConnectError::Serialization(e.to_string())
57 }
58}
59
60impl From<rusqlite::Error> for ConnectError {
61 fn from(e: rusqlite::Error) -> Self {
62 ConnectError::Database(e.to_string())
63 }
64}
65
66#[cfg(feature = "http")]
67impl From<reqwest::Error> for ConnectError {
68 fn from(e: reqwest::Error) -> Self {
69 ConnectError::Http(e.to_string())
70 }
71}