Skip to main content

brz_memcache/
error.rs

1use std::io;
2
3/// Result alias used throughout the crate.
4pub type Result<T> = std::result::Result<T, Error>;
5
6/// Errors returned by the memcached client.
7#[derive(Debug, thiserror::Error)]
8#[non_exhaustive]
9pub enum Error {
10    /// The cache-service YAML or selected namespace was invalid.
11    #[error(transparent)]
12    CacheServiceConfig(#[from] crate::cacheservice::CacheServiceError),
13
14    /// Transport-level I/O error on an established connection.
15    #[error("io error: {0}")]
16    Io(#[source] io::Error),
17
18    /// An operation exceeded the configured timeout.
19    #[error("operation timed out")]
20    Timeout,
21
22    /// The physical node has not connected yet or is reconnecting.
23    #[error("backend connection is unavailable")]
24    Unavailable,
25
26    /// The physical node's bounded request queue is full.
27    #[error("backend request capacity is exhausted")]
28    Overloaded,
29
30    /// The server reported a `SERVER_ERROR` (text) or a server-side status.
31    #[error("server error: {0}")]
32    Server(String),
33
34    /// The server reported a `CLIENT_ERROR` / invalid-argument style failure.
35    #[error("client error: {0}")]
36    Client(String),
37
38    /// The response could not be parsed / violated the protocol.
39    #[error("protocol error: {0}")]
40    Protocol(String),
41
42    /// The connection is out of sync: a response frame did not match the
43    /// request that was sent (e.g. a leftover frame from a timed-out
44    /// operation). The connection must be dropped, not reused.
45    #[error("desynced connection: {0}")]
46    Desynced(String),
47
48    /// The key was empty, too long, or contained control/space characters.
49    #[error("invalid key: {0}")]
50    InvalidKey(&'static str),
51
52    /// A stored value used a feature this client does not decode
53    /// (QuickLZ compression or Java object serialization).
54    #[error("unsupported value encoding: {0}")]
55    Unsupported(&'static str),
56
57    /// A typed decode of a [`crate::Value`] did not match the stored flags.
58    #[error("value decode error: {0}")]
59    Decode(String),
60}
61
62impl From<io::Error> for Error {
63    fn from(err: io::Error) -> Self {
64        Error::Io(err)
65    }
66}