Skip to content

Commit 4f37625

Browse files
committed
Shorten error variant names
No reason to repeat Error
1 parent fe14c82 commit 4f37625

File tree

7 files changed

+72
-72
lines changed

7 files changed

+72
-72
lines changed

src/error.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,15 @@ impl DbErrorNew for DbError {
124124

125125
fn new_connect<T>(fields: Vec<(u8, String)>) -> result::Result<T, ConnectError> {
126126
match DbError::new_raw(fields) {
127-
Ok(err) => Err(ConnectError::DbError(Box::new(err))),
128-
Err(()) => Err(ConnectError::IoError(::bad_response())),
127+
Ok(err) => Err(ConnectError::Db(Box::new(err))),
128+
Err(()) => Err(ConnectError::Io(::bad_response())),
129129
}
130130
}
131131

132132
fn new<T>(fields: Vec<(u8, String)>) -> Result<T> {
133133
match DbError::new_raw(fields) {
134-
Ok(err) => Err(Error::DbError(Box::new(err))),
135-
Err(()) => Err(Error::IoError(::bad_response())),
134+
Ok(err) => Err(Error::Db(Box::new(err))),
135+
Err(()) => Err(Error::Io(::bad_response())),
136136
}
137137
}
138138
}
@@ -180,7 +180,7 @@ pub enum ConnectError {
180180
/// The `ConnectParams` was missing a user.
181181
MissingUser,
182182
/// An error from the Postgres server itself.
183-
DbError(Box<DbError>),
183+
Db(Box<DbError>),
184184
/// A password was required but not provided in the `ConnectParams`.
185185
MissingPassword,
186186
/// The Postgres server requested an authentication method not supported
@@ -189,19 +189,19 @@ pub enum ConnectError {
189189
/// The Postgres server does not support SSL encryption.
190190
NoSslSupport,
191191
/// An error initializing the SSL session.
192-
SslError(Box<error::Error + Sync + Send>),
192+
Ssl(Box<error::Error + Sync + Send>),
193193
/// An error communicating with the server.
194-
IoError(io::Error),
194+
Io(io::Error),
195195
}
196196

197197
impl fmt::Display for ConnectError {
198198
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
199199
try!(fmt.write_str(error::Error::description(self)));
200200
match *self {
201201
ConnectError::BadConnectParams(ref msg) => write!(fmt, ": {}", msg),
202-
ConnectError::DbError(ref err) => write!(fmt, ": {}", err),
203-
ConnectError::SslError(ref err) => write!(fmt, ": {}", err),
204-
ConnectError::IoError(ref err) => write!(fmt, ": {}", err),
202+
ConnectError::Db(ref err) => write!(fmt, ": {}", err),
203+
ConnectError::Ssl(ref err) => write!(fmt, ": {}", err),
204+
ConnectError::Io(ref err) => write!(fmt, ": {}", err),
205205
_ => Ok(()),
206206
}
207207
}
@@ -212,45 +212,45 @@ impl error::Error for ConnectError {
212212
match *self {
213213
ConnectError::BadConnectParams(_) => "Error creating `ConnectParams`",
214214
ConnectError::MissingUser => "User missing in `ConnectParams`",
215-
ConnectError::DbError(_) => "Error reported by Postgres",
215+
ConnectError::Db(_) => "Error reported by Postgres",
216216
ConnectError::MissingPassword => {
217217
"The server requested a password but none was provided"
218218
}
219219
ConnectError::UnsupportedAuthentication => {
220220
"The server requested an unsupported authentication method"
221221
}
222222
ConnectError::NoSslSupport => "The server does not support SSL",
223-
ConnectError::SslError(_) => "Error initiating SSL session",
224-
ConnectError::IoError(_) => "Error communicating with the server",
223+
ConnectError::Ssl(_) => "Error initiating SSL session",
224+
ConnectError::Io(_) => "Error communicating with the server",
225225
}
226226
}
227227

228228
fn cause(&self) -> Option<&error::Error> {
229229
match *self {
230230
ConnectError::BadConnectParams(ref err) => Some(&**err),
231-
ConnectError::DbError(ref err) => Some(&**err),
232-
ConnectError::SslError(ref err) => Some(&**err),
233-
ConnectError::IoError(ref err) => Some(err),
231+
ConnectError::Db(ref err) => Some(&**err),
232+
ConnectError::Ssl(ref err) => Some(&**err),
233+
ConnectError::Io(ref err) => Some(err),
234234
_ => None,
235235
}
236236
}
237237
}
238238

239239
impl From<io::Error> for ConnectError {
240240
fn from(err: io::Error) -> ConnectError {
241-
ConnectError::IoError(err)
241+
ConnectError::Io(err)
242242
}
243243
}
244244

245245
impl From<DbError> for ConnectError {
246246
fn from(err: DbError) -> ConnectError {
247-
ConnectError::DbError(Box::new(err))
247+
ConnectError::Db(Box::new(err))
248248
}
249249
}
250250

251251
impl From<byteorder::Error> for ConnectError {
252252
fn from(err: byteorder::Error) -> ConnectError {
253-
ConnectError::IoError(From::from(err))
253+
ConnectError::Io(From::from(err))
254254
}
255255
}
256256

@@ -272,9 +272,9 @@ pub enum ErrorPosition {
272272
#[derive(Debug)]
273273
pub enum Error {
274274
/// An error reported by the Postgres server.
275-
DbError(Box<DbError>),
275+
Db(Box<DbError>),
276276
/// An error communicating with the Postgres server.
277-
IoError(io::Error),
277+
Io(io::Error),
278278
/// An attempt was made to convert between incompatible Rust and Postgres
279279
/// types.
280280
WrongType(Type),
@@ -286,8 +286,8 @@ impl fmt::Display for Error {
286286
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
287287
try!(fmt.write_str(error::Error::description(self)));
288288
match *self {
289-
Error::DbError(ref err) => write!(fmt, ": {}", err),
290-
Error::IoError(ref err) => write!(fmt, ": {}", err),
289+
Error::Db(ref err) => write!(fmt, ": {}", err),
290+
Error::Io(ref err) => write!(fmt, ": {}", err),
291291
Error::WrongType(ref ty) => write!(fmt, ": saw type {:?}", ty),
292292
Error::Conversion(ref err) => write!(fmt, ": {}", err),
293293
}
@@ -297,17 +297,17 @@ impl fmt::Display for Error {
297297
impl error::Error for Error {
298298
fn description(&self) -> &str {
299299
match *self {
300-
Error::DbError(_) => "Error reported by Postgres",
301-
Error::IoError(_) => "Error communicating with the server",
300+
Error::Db(_) => "Error reported by Postgres",
301+
Error::Io(_) => "Error communicating with the server",
302302
Error::WrongType(_) => "Unexpected type",
303303
Error::Conversion(_) => "Error converting between Postgres and Rust types",
304304
}
305305
}
306306

307307
fn cause(&self) -> Option<&error::Error> {
308308
match *self {
309-
Error::DbError(ref err) => Some(&**err),
310-
Error::IoError(ref err) => Some(err),
309+
Error::Db(ref err) => Some(&**err),
310+
Error::Io(ref err) => Some(err),
311311
Error::Conversion(ref err) => Some(&**err),
312312
_ => None,
313313
}
@@ -316,19 +316,19 @@ impl error::Error for Error {
316316

317317
impl From<DbError> for Error {
318318
fn from(err: DbError) -> Error {
319-
Error::DbError(Box::new(err))
319+
Error::Db(Box::new(err))
320320
}
321321
}
322322

323323
impl From<io::Error> for Error {
324324
fn from(err: io::Error) -> Error {
325-
Error::IoError(err)
325+
Error::Io(err)
326326
}
327327
}
328328

329329
impl From<byteorder::Error> for Error {
330330
fn from(err: byteorder::Error) -> Error {
331-
Error::IoError(From::from(err))
331+
Error::Io(From::from(err))
332332
}
333333
}
334334

src/lib.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ impl IsolationLevel {
346346
} else if raw.eq_ignore_ascii_case("SERIALIZABLE") {
347347
Ok(IsolationLevel::Serializable)
348348
} else {
349-
Err(Error::IoError(bad_response()))
349+
Err(Error::Io(bad_response()))
350350
}
351351
}
352352
}
@@ -444,7 +444,7 @@ impl InnerConnection {
444444
}
445445
ReadyForQuery { .. } => break,
446446
ErrorResponse { fields } => return DbError::new_connect(fields),
447-
_ => return Err(ConnectError::IoError(bad_response())),
447+
_ => return Err(ConnectError::Io(bad_response())),
448448
}
449449
}
450450

@@ -464,10 +464,10 @@ impl InnerConnection {
464464
t.typnamespace = n.oid \
465465
WHERE t.oid = $1") {
466466
Ok(..) => return Ok(()),
467-
Err(Error::IoError(e)) => return Err(ConnectError::IoError(e)),
467+
Err(Error::Io(e)) => return Err(ConnectError::Io(e)),
468468
// Range types weren't added until Postgres 9.2, so pg_range may not exist
469-
Err(Error::DbError(ref e)) if e.code == SqlState::UndefinedTable => {}
470-
Err(Error::DbError(e)) => return Err(ConnectError::DbError(e)),
469+
Err(Error::Db(ref e)) if e.code == SqlState::UndefinedTable => {}
470+
Err(Error::Db(e)) => return Err(ConnectError::Db(e)),
471471
_ => unreachable!(),
472472
}
473473

@@ -478,8 +478,8 @@ impl InnerConnection {
478478
ON t.typnamespace = n.oid \
479479
WHERE t.oid = $1") {
480480
Ok(..) => Ok(()),
481-
Err(Error::IoError(e)) => Err(ConnectError::IoError(e)),
482-
Err(Error::DbError(e)) => Err(ConnectError::DbError(e)),
481+
Err(Error::Io(e)) => Err(ConnectError::Io(e)),
482+
Err(Error::Db(e)) => Err(ConnectError::Db(e)),
483483
_ => unreachable!(),
484484
}
485485
}
@@ -567,13 +567,13 @@ impl InnerConnection {
567567
AuthenticationGSS |
568568
AuthenticationSSPI => return Err(ConnectError::UnsupportedAuthentication),
569569
ErrorResponse { fields } => return DbError::new_connect(fields),
570-
_ => return Err(ConnectError::IoError(bad_response())),
570+
_ => return Err(ConnectError::Io(bad_response())),
571571
}
572572

573573
match try!(self.read_message()) {
574574
AuthenticationOk => Ok(()),
575575
ErrorResponse { fields } => return DbError::new_connect(fields),
576-
_ => return Err(ConnectError::IoError(bad_response())),
576+
_ => return Err(ConnectError::Io(bad_response())),
577577
}
578578
}
579579

@@ -1336,13 +1336,13 @@ fn read_rows(conn: &mut InnerConnection, buf: &mut VecDeque<Vec<Option<Vec<u8>>>
13361336
_ => {}
13371337
}
13381338
}
1339-
return Err(Error::IoError(std_io::Error::new(std_io::ErrorKind::InvalidInput,
1339+
return Err(Error::Io(std_io::Error::new(std_io::ErrorKind::InvalidInput,
13401340
"COPY queries cannot be directly \
13411341
executed")));
13421342
}
13431343
_ => {
13441344
conn.desynchronized = true;
1345-
return Err(Error::IoError(bad_response()));
1345+
return Err(Error::Io(bad_response()));
13461346
}
13471347
}
13481348
}

src/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ macro_rules! try_desync {
1313
macro_rules! check_desync {
1414
($e:expr) => ({
1515
if $e.is_desynchronized() {
16-
return Err(::error::Error::IoError(::desynchronized()));
16+
return Err(::error::Error::Io(::desynchronized()));
1717
}
1818
})
1919
}
@@ -22,6 +22,6 @@ macro_rules! bad_response {
2222
($s:expr) => ({
2323
debug!("Bad response at {}:{}", file!(), line!());
2424
$s.desynchronized = true;
25-
return Err(::error::Error::IoError(::bad_response()));
25+
return Err(::error::Error::Io(::bad_response()));
2626
})
2727
}

src/notification.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl<'a> Iterator for BlockingIter<'a> {
115115
}
116116

117117
if conn.is_desynchronized() {
118-
return Some(Err(Error::IoError(desynchronized())));
118+
return Some(Err(Error::Io(desynchronized())));
119119
}
120120

121121
match conn.read_message_with_notification() {
@@ -126,7 +126,7 @@ impl<'a> Iterator for BlockingIter<'a> {
126126
payload: payload,
127127
}))
128128
}
129-
Err(err) => Some(Err(Error::IoError(err))),
129+
Err(err) => Some(Err(Error::Io(err))),
130130
_ => unreachable!(),
131131
}
132132
}
@@ -150,7 +150,7 @@ impl<'a> Iterator for TimeoutIter<'a> {
150150
}
151151

152152
if conn.is_desynchronized() {
153-
return Some(Err(Error::IoError(desynchronized())));
153+
return Some(Err(Error::Io(desynchronized())));
154154
}
155155

156156
match conn.read_message_with_notification_timeout(self.timeout) {
@@ -162,7 +162,7 @@ impl<'a> Iterator for TimeoutIter<'a> {
162162
}))
163163
}
164164
Ok(None) => None,
165-
Err(err) => Some(Err(Error::IoError(err))),
165+
Err(err) => Some(Err(Error::Io(err))),
166166
_ => unreachable!(),
167167
}
168168
}

src/priv_io.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,6 @@ pub fn initialize_stream(params: &ConnectParams,
180180

181181
match negotiator.negotiate_ssl(host, socket) {
182182
Ok(stream) => Ok(stream),
183-
Err(err) => Err(ConnectError::SslError(err)),
183+
Err(err) => Err(ConnectError::Ssl(err)),
184184
}
185185
}

0 commit comments

Comments
 (0)