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
use std::error;
use std::fmt;
use std::io;
use std::result;
use std::string::FromUtf8Error;
use std::fmt::Display;
use frame::frame_error::CDRSError;
use compression::CompressionError;
use uuid::ParseError;
pub type Result<T> = result::Result<T, Error>;
#[derive(Debug)]
pub enum Error {
Io(io::Error),
UUIDParse(ParseError),
General(String),
FromUtf8(FromUtf8Error),
Compression(CompressionError),
Server(CDRSError),
}
pub fn column_is_empty_err<T: Display>(column_name: T) -> Error {
Error::General(format!("Column or UDT property '{}' is empty", column_name))
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Error::Io(ref err) => write!(f, "IO error: {}", err),
Error::Compression(ref err) => write!(f, "Compressor error: {}", err),
Error::Server(ref err) => write!(f, "Server error: {:?}", err.message),
Error::FromUtf8(ref err) => write!(f, "FromUtf8Error error: {:?}", err),
Error::UUIDParse(ref err) => write!(f, "UUIDParse error: {:?}", err),
Error::General(ref err) => write!(f, "GeneralParsing error: {:?}", err),
}
}
}
impl error::Error for Error {
fn description(&self) -> &str {
match *self {
Error::Io(ref err) => err.description(),
Error::Compression(ref err) => err.description(),
Error::Server(ref err) => err.message.as_str(),
Error::FromUtf8(ref err) => err.description(),
Error::UUIDParse(_) => "UUID Parse Error",
Error::General(ref err) => err.as_str(),
}
}
}
impl From<io::Error> for Error {
fn from(err: io::Error) -> Error {
Error::Io(err)
}
}
impl From<CDRSError> for Error {
fn from(err: CDRSError) -> Error {
Error::Server(err)
}
}
impl From<CompressionError> for Error {
fn from(err: CompressionError) -> Error {
Error::Compression(err)
}
}
impl From<FromUtf8Error> for Error {
fn from(err: FromUtf8Error) -> Error {
Error::FromUtf8(err)
}
}
impl From<ParseError> for Error {
fn from(err: ParseError) -> Error {
Error::UUIDParse(err)
}
}
impl From<String> for Error {
fn from(err: String) -> Error {
Error::General(err)
}
}
impl<'a> From<&'a str> for Error {
fn from(err: &str) -> Error {
Error::General(err.to_string())
}
}