ringline_momento/error.rs
1//! Error types for the Momento client.
2
3use std::io;
4
5/// Result type for Momento operations.
6pub type Result<T> = std::result::Result<T, Error>;
7
8/// Errors that can occur when using the Momento client.
9///
10/// Marked `#[non_exhaustive]` because the crate is still evolving and new
11/// transport / protocol error kinds are expected. Downstream `match`
12/// blocks must include a wildcard arm.
13#[derive(Debug, thiserror::Error)]
14#[non_exhaustive]
15pub enum Error {
16 /// The connection was closed before a response was received.
17 #[error("connection closed")]
18 ConnectionClosed,
19
20 /// Not authenticated (auth command not yet completed).
21 #[error("not authenticated")]
22 NotAuthenticated,
23
24 /// Authentication with Momento failed.
25 #[error("authentication failed: {0}")]
26 AuthFailed(String),
27
28 /// Protocol-level error (malformed response, unexpected message type).
29 #[error("protocol error: {0}")]
30 Protocol(String),
31
32 /// Configuration error (bad token, missing env var).
33 #[error("config error: {0}")]
34 Config(String),
35
36 /// I/O error during send or recv.
37 #[error("io error: {0}")]
38 Io(#[from] io::Error),
39
40 /// `recv()` was called with no in-flight requests.
41 #[error("no pending requests")]
42 NoPending,
43
44 /// All connections in the pool are down and reconnection failed.
45 #[error("all connections failed")]
46 AllConnectionsFailed,
47
48 /// The in-flight pending-op map reached `max_in_flight`. Drain via
49 /// `recv()` before issuing more `fire_*` calls. Configurable via
50 /// [`crate::ClientBuilder::max_in_flight`].
51 #[error("too many in-flight operations")]
52 TooManyInFlight,
53
54 /// A sequential API call ([`crate::Client::get`] / `set` / `delete`)
55 /// was issued while one or more `fire_*` ops were still in flight.
56 /// Momento is multiplexed and `recv()` returns whatever `message_id`
57 /// arrives first; the convenience APIs discard the id/key and would
58 /// silently return data for the wrong request. Drain `recv()` until
59 /// `pending_count() == 0` before calling the sequential API, or use
60 /// `fire_*` + `recv()` exclusively.
61 #[error("sequential API requires no in-flight fire_* ops; drain recv() first")]
62 PendingOpsInFlight,
63}