redis_asyncx/error.rs
1//! Custom error handling for Redis client and a specialized Result type
2//! used as the return type for Redis operations.
3
4/// Represents errors that can occur when working with Redis.
5#[derive(thiserror::Error, Debug)]
6pub enum RedisError {
7 #[error("error from io")]
8 Io(#[from] std::io::Error),
9 /// An incomplete frame was received when reading from the socket.
10 #[error("incomplete frame")]
11 IncompleteFrame,
12 /// An invalid frame was received when reading from the socket. According to RESP3 spec.
13 #[error("invalid frame")]
14 InvalidFrame,
15 /// So that we can use `?` operator to convert from `std::str::Utf8Error`
16 #[error("utf8 error")]
17 Utf8(#[from] std::str::Utf8Error),
18 /// So that we can use `?` operator to convert from `std::num::ParseIntError`
19 #[error("parseint error")]
20 ParseInt(#[from] std::num::ParseIntError),
21 #[error("unexpected response type")]
22 UnexpectedResponseType,
23 /// All other errors are converted to anyhow::Error
24 /// This is a catch-all error type that can be used to wrap any other error.
25 #[error(transparent)]
26 Other(#[from] anyhow::Error), // source and Display delegate to anyhow::Error
27 /// Last resort error type. This is used when we don't know what went wrong.
28 /// Should avoid using this error type if possible.
29 #[error("unknown error")]
30 Unknown,
31}
32
33/// A specialized `Result` type for Redis operations.
34pub type Result<T> = anyhow::Result<T, RedisError>;