veddb_client/
error.rs

1//! Error types for VedDB client
2
3use thiserror::Error;
4
5/// Error type for VedDB client operations
6#[derive(Debug, Error)]
7pub enum Error {
8    /// Network or connection error
9    #[error("Connection error: {0}")]
10    Connection(String),
11
12    /// Protocol error
13    #[error("Protocol error: {0}")]
14    Protocol(String),
15
16    /// Server returned an error
17    #[error("Server error: {0}")]
18    Server(String),
19
20    /// Operation timed out
21    #[error("Operation timed out: {0}")]
22    Timeout(#[from] tokio::time::error::Elapsed),
23
24    /// I/O error
25    #[error("I/O error: {0}")]
26    Io(#[from] std::io::Error),
27
28    /// Serialization/Deserialization error
29    #[error("Serialization error: {0}")]
30    Serialization(String),
31
32    /// Invalid argument provided
33    #[error("Invalid argument: {0}")]
34    InvalidArgument(String),
35
36    /// Key not found
37    #[error("Key not found")]
38    KeyNotFound,
39
40    /// Connection pool exhausted
41    #[error("Connection pool exhausted")]
42    PoolExhausted,
43
44    /// Invalid response from server
45    #[error("Invalid response: {0}")]
46    InvalidResponse(String),
47
48    /// Authentication failed
49    #[error("Authentication failed")]
50    AuthenticationFailed,
51
52    /// Not connected to server
53    #[error("Not connected")]
54    NotConnected,
55
56    /// Operation not supported
57    #[error("Operation not supported")]
58    NotSupported,
59
60    /// JSON serialization/deserialization error
61    #[error("JSON error: {0}")]
62    Json(#[from] serde_json::Error),
63
64    /// Other errors
65    #[error("{0}")]
66    Other(String),
67}
68
69impl Error {
70    /// Create a connection error
71    pub fn connection<S: Into<String>>(msg: S) -> Self {
72        Error::Connection(msg.into())
73    }
74
75    /// Create a protocol error
76    pub fn protocol<S: Into<String>>(msg: S) -> Self {
77        Error::Protocol(msg.into())
78    }
79
80    /// Create a server error
81    pub fn server<S: Into<String>>(msg: S) -> Self {
82        Error::Server(msg.into())
83    }
84
85    /// Create an invalid argument error
86    pub fn invalid_argument<S: Into<String>>(msg: S) -> Self {
87        Error::InvalidArgument(msg.into())
88    }
89
90    /// Create an invalid response error
91    pub fn invalid_response<S: Into<String>>(msg: S) -> Self {
92        Error::InvalidResponse(msg.into())
93    }
94
95    /// Create an other error
96    pub fn other<S: Into<String>>(msg: S) -> Self {
97        Error::Other(msg.into())
98    }
99}
100
101impl From<String> for Error {
102    fn from(s: String) -> Self {
103        Error::Other(s)
104    }
105}
106
107impl From<&str> for Error {
108    fn from(s: &str) -> Self {
109        Error::Other(s.to_string())
110    }
111}