1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
use std::error; use std::error::Error; use std::fmt; use std::io; use std::num; use std::str; use std::sync::mpsc; use types::{PubSubType, SenderType}; #[derive(Debug, Clone)] pub enum ParsingError { BadIdentifier(String), } impl fmt::Display for ParsingError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { ParsingError::BadIdentifier(ref err) => write!(f, "Invalid identifer: {}", err), } } } impl error::Error for ParsingError { fn description(&self) -> &str { match *self { ParsingError::BadIdentifier(ref err) => err, } } fn cause(&self) -> Option<&error::Error> { match *self { ParsingError::BadIdentifier(ref _err) => Some(self), } } } #[derive(Debug)] pub enum RedisError { Io(io::Error), Utf8(str::Utf8Error), ParseInt(num::ParseIntError), Parse(ParsingError), Response(String), MpscRecv(mpsc::RecvError), MpscSendBytes(mpsc::SendError<(SenderType, u32, Vec<u8>)>), MpscSendPubSubBytes(mpsc::SendError<(PubSubType, u32, Vec<u8>)>), MpscTryRecv(mpsc::TryRecvError), } impl Clone for RedisError { fn clone(&self) -> RedisError { match *self { RedisError::Io(ref err) => RedisError::Io(io::Error::new(err.kind(), err.description())), RedisError::Utf8(ref err) => RedisError::Utf8(err.clone()), RedisError::ParseInt(ref err) => RedisError::ParseInt(err.clone()), RedisError::Parse(ref err) => RedisError::Parse(err.clone()), RedisError::Response(ref err) => RedisError::Response(err.clone()), RedisError::MpscRecv(ref err) => RedisError::MpscRecv(err.clone()), RedisError::MpscSendBytes(ref err) => RedisError::MpscSendBytes(err.clone()), RedisError::MpscSendPubSubBytes(ref err) => RedisError::MpscSendPubSubBytes(err.clone()), RedisError::MpscTryRecv(ref err) => RedisError::MpscTryRecv(err.clone()), } } } impl fmt::Display for RedisError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { RedisError::Io(ref err) => write!(f, "IO error: {}", err), RedisError::Utf8(ref err) => write!(f, "Utf8 error: {}", err), RedisError::ParseInt(ref err) => write!(f, "Parse Int error: {}", err), RedisError::Parse(ref err) => write!(f, "Parsing error: {}", err), RedisError::Response(ref err) => write!(f, "Response error: {}", err), RedisError::MpscRecv(ref err) => write!(f, "MpscRecv error: {}", err), RedisError::MpscSendBytes(ref err) => write!(f, "MpscSendBytes error: {}", err), RedisError::MpscSendPubSubBytes(ref err) => write!(f, "MpscSendPubSubBytes error: {}", err), RedisError::MpscTryRecv(ref err) => write!(f, "MpscTryRecv error: {}", err), } } } impl error::Error for RedisError { fn description(&self) -> &str { match *self { RedisError::Io(ref err) => err.description(), RedisError::Utf8(ref err) => err.description(), RedisError::ParseInt(ref err) => err.description(), RedisError::Parse(ref err) => err.description(), RedisError::Response(ref err) => err, RedisError::MpscRecv(ref err) => err.description(), RedisError::MpscSendBytes(ref err) => err.description(), RedisError::MpscSendPubSubBytes(ref err) => err.description(), RedisError::MpscTryRecv(ref err) => err.description(), } } fn cause(&self) -> Option<&error::Error> { match *self { RedisError::Io(ref err) => Some(err), RedisError::Utf8(ref err) => Some(err), RedisError::ParseInt(ref err) => Some(err), RedisError::Parse(ref err) => Some(err), RedisError::Response(ref _err) => Some(self), RedisError::MpscRecv(ref err) => Some(err), RedisError::MpscSendBytes(ref err) => Some(err), RedisError::MpscSendPubSubBytes(ref err) => Some(err), RedisError::MpscTryRecv(ref err) => Some(err), } } } impl From<io::Error> for RedisError { fn from(err: io::Error) -> RedisError { RedisError::Io(err) } } impl From<str::Utf8Error> for RedisError { fn from(err: str::Utf8Error) -> RedisError { RedisError::Utf8(err) } } impl From<num::ParseIntError> for RedisError { fn from(err: num::ParseIntError) -> RedisError { RedisError::ParseInt(err) } } impl From<ParsingError> for RedisError { fn from(err: ParsingError) -> RedisError { RedisError::Parse(err) } } impl From<String> for RedisError { fn from(err: String) -> RedisError { RedisError::Response(err) } } impl From<mpsc::RecvError> for RedisError { fn from(err: mpsc::RecvError) -> RedisError { RedisError::MpscRecv(err) } } impl From<mpsc::SendError<(SenderType, u32, Vec<u8>)>> for RedisError { fn from(err: mpsc::SendError<(SenderType, u32, Vec<u8>)>) -> RedisError { RedisError::MpscSendBytes(err) } } impl From<mpsc::SendError<(PubSubType, u32, Vec<u8>)>> for RedisError { fn from(err: mpsc::SendError<(PubSubType, u32, Vec<u8>)>) -> RedisError { RedisError::MpscSendPubSubBytes(err) } } impl From<mpsc::TryRecvError> for RedisError { fn from(err: mpsc::TryRecvError) -> RedisError { RedisError::MpscTryRecv(err) } }