1use std::io;
3
4use derive_more::{Display, From};
5use ntex::{connect, util::ByteString, util::Either};
6
7use super::codec::Response;
8
9#[derive(Debug, Display)]
10pub enum Error {
12 #[display(fmt = "Redis server response error: {}", _0)]
14 Parse(String),
15
16 #[display(fmt = "Io error: {:?}", _0)]
18 PeerGone(Option<io::Error>),
19}
20
21impl std::error::Error for Error {}
22
23impl Clone for Error {
24 fn clone(&self) -> Self {
25 match self {
26 Error::Parse(_) => Error::Parse(String::new()),
27 Error::PeerGone(_) => Error::PeerGone(None),
28 }
29 }
30}
31
32impl From<io::Error> for Error {
33 fn from(err: io::Error) -> Error {
34 Error::PeerGone(Some(err))
35 }
36}
37
38impl From<Either<Error, io::Error>> for Error {
39 fn from(err: Either<Error, io::Error>) -> Error {
40 match err {
41 Either::Left(err) => err,
42 Either::Right(err) => Error::PeerGone(Some(err)),
43 }
44 }
45}
46
47#[derive(Debug, Display, From, Clone)]
48pub enum ConnectError {
50 Unauthorized,
52
53 Command(CommandError),
55
56 Connect(connect::ConnectError),
58}
59
60impl std::error::Error for ConnectError {}
61
62#[derive(Debug, Display, From, Clone)]
63pub enum CommandError {
65 Error(ByteString),
67
68 #[display(fmt = "Command output parse error: {}", _0)]
70 Output(&'static str, Response),
71
72 Protocol(Error),
74}
75
76impl std::error::Error for CommandError {}
77
78impl From<Either<Error, io::Error>> for CommandError {
79 fn from(err: Either<Error, io::Error>) -> CommandError {
80 Into::<Error>::into(err).into()
81 }
82}