1use std::io;
3
4use derive_more::{Display, From};
5use crate::bytes::ByteString;
6use super::codec_redis::Response;
7
8#[derive(Debug, Display)]
9pub enum Error {
11 #[display(fmt = "Redis server response error: {}", _0)]
13 Parse(String),
14
15 #[display(fmt = "Io error: {:?}", _0)]
17 PeerGone(Option<io::Error>),
18
19 #[display(fmt = "Command error: {:?}", _0)]
20 Command(String),
21
22 #[display(fmt = "Recv error: {:?}", _0)]
23 Recv(String),
24}
25
26impl std::error::Error for Error {}
27
28impl Clone for Error {
29 fn clone(&self) -> Self {
30 match self {
31 Error::Parse(s) => Error::Parse(s.clone()),
32 Error::PeerGone(_) => Error::PeerGone(None),
33 Error::Command(v)=> Error::Command(v.clone()),
34 Error::Recv(v)=> Error::Recv(v.clone()),
35 }
36 }
37}
38
39impl From<io::Error> for Error {
40 fn from(err: io::Error) -> Error {
41 Error::PeerGone(Some(err))
42 }
43}
44
45impl From<CommandError> for Error{
46 fn from(arg: CommandError) -> Self {
47 Error::Command(format!("{:?}",arg))
48 }
49}
50
51#[derive(Debug, Display, From)]
52pub enum ConnectError {
54 Unauthorized,
56 Command(CommandError),
58 Connect(String),
60}
61
62impl std::error::Error for ConnectError {}
63
64impl From<std::io::Error> for ConnectError {
65 fn from(arg: std::io::Error) -> Self {
66 ConnectError::Connect(arg.to_string())
67 }
68}
69
70#[derive(Debug, Display, From)]
71pub enum CommandError {
73 Error(ByteString),
75
76 #[display(fmt = "Command output parse error: {}", _0)]
78 Output(&'static str, Response),
79
80 Protocol(Error),
82}
83
84impl std::error::Error for CommandError {}
85
86impl From<std::io::Error> for CommandError{
87 fn from(arg: io::Error) -> Self {
88 CommandError::Protocol(Error::PeerGone(Some(arg)))
89 }
90}