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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
use hyper::error as herror;
use std::error::Error;
use std::fmt;
use std::io::Error as IOError;
use url::ParseError;
use webdriver::error as wderror;
#[derive(Debug)]
pub enum NewSessionError {
BadWebdriverUrl(ParseError),
Failed(herror::Error),
Lost(IOError),
NotW3C(serde_json::Value),
SessionNotCreated(wderror::WebDriverError),
}
impl Error for NewSessionError {
fn description(&self) -> &str {
match *self {
NewSessionError::BadWebdriverUrl(..) => "webdriver url is invalid",
NewSessionError::Failed(..) => "webdriver server did not respond",
NewSessionError::Lost(..) => "webdriver server disconnected",
NewSessionError::NotW3C(..) => "webdriver server gave non-conformant response",
NewSessionError::SessionNotCreated(..) => "webdriver did not create session",
}
}
fn cause(&self) -> Option<&dyn Error> {
match *self {
NewSessionError::BadWebdriverUrl(ref e) => Some(e),
NewSessionError::Failed(ref e) => Some(e),
NewSessionError::Lost(ref e) => Some(e),
NewSessionError::NotW3C(..) => None,
NewSessionError::SessionNotCreated(ref e) => Some(e),
}
}
}
impl fmt::Display for NewSessionError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}: ", self.description())?;
match *self {
NewSessionError::BadWebdriverUrl(ref e) => write!(f, "{}", e),
NewSessionError::Failed(ref e) => write!(f, "{}", e),
NewSessionError::Lost(ref e) => write!(f, "{}", e),
NewSessionError::NotW3C(ref e) => write!(f, "{:?}", e),
NewSessionError::SessionNotCreated(ref e) => write!(f, "{}", e),
}
}
}
#[derive(Debug)]
pub enum CmdError {
Standard(wderror::WebDriverError),
NoSuchElement(wderror::WebDriverError),
BadUrl(ParseError),
Failed(herror::Error),
Lost(IOError),
NotJson(String),
Json(serde_json::Error),
NotW3C(serde_json::Value),
InvalidArgument(String, String),
ImageDecodeError(::base64::DecodeError),
}
impl CmdError {
pub fn is_miss(&self) -> bool {
if let CmdError::NoSuchElement(..) = *self {
true
} else {
false
}
}
}
impl Error for CmdError {
fn description(&self) -> &str {
match *self {
CmdError::Standard(..) => "webdriver returned error",
CmdError::NoSuchElement(..) => "no element found matching selector",
CmdError::BadUrl(..) => "bad url provided",
CmdError::Failed(..) => "webdriver could not be reached",
CmdError::Lost(..) => "webdriver connection lost",
CmdError::NotJson(..) => "webdriver returned invalid response",
CmdError::Json(..) => "webdriver returned incoherent response",
CmdError::NotW3C(..) => "webdriver returned non-conforming response",
CmdError::InvalidArgument(..) => "invalid argument provided",
CmdError::ImageDecodeError(..) => "error decoding image",
}
}
fn cause(&self) -> Option<&dyn Error> {
match *self {
CmdError::Standard(ref e) | CmdError::NoSuchElement(ref e) => Some(e),
CmdError::BadUrl(ref e) => Some(e),
CmdError::Failed(ref e) => Some(e),
CmdError::Lost(ref e) => Some(e),
CmdError::Json(ref e) => Some(e),
CmdError::ImageDecodeError(ref e) => Some(e),
CmdError::NotJson(_) | CmdError::NotW3C(_) | CmdError::InvalidArgument(..) => None,
}
}
}
impl fmt::Display for CmdError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}: ", self.description())?;
match *self {
CmdError::Standard(ref e) | CmdError::NoSuchElement(ref e) => write!(f, "{}", e),
CmdError::BadUrl(ref e) => write!(f, "{}", e),
CmdError::Failed(ref e) => write!(f, "{}", e),
CmdError::Lost(ref e) => write!(f, "{}", e),
CmdError::NotJson(ref e) => write!(f, "{}", e),
CmdError::Json(ref e) => write!(f, "{}", e),
CmdError::NotW3C(ref e) => write!(f, "{:?}", e),
CmdError::ImageDecodeError(ref e) => write!(f, "{:?}", e),
CmdError::InvalidArgument(ref arg, ref msg) => {
write!(f, "Invalid argument `{}`: {}", arg, msg)
}
}
}
}
impl From<IOError> for CmdError {
fn from(e: IOError) -> Self {
CmdError::Lost(e)
}
}
impl From<ParseError> for CmdError {
fn from(e: ParseError) -> Self {
CmdError::BadUrl(e)
}
}
impl From<herror::Error> for CmdError {
fn from(e: herror::Error) -> Self {
CmdError::Failed(e)
}
}
impl From<wderror::WebDriverError> for CmdError {
fn from(e: wderror::WebDriverError) -> Self {
if let wderror::WebDriverError {
error: wderror::ErrorStatus::NoSuchElement,
..
} = e
{
CmdError::NoSuchElement(e)
} else {
CmdError::Standard(e)
}
}
}
impl From<serde_json::Error> for CmdError {
fn from(e: serde_json::Error) -> Self {
CmdError::Json(e)
}
}