Skip to content

Commit 5258013

Browse files
committed
Make error Display impls more descriptive
Closes #134
1 parent d5fd591 commit 5258013

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/error.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ impl fmt::Display for ConnectError {
217217
try!(fmt.write_str(error::Error::description(self)));
218218
match *self {
219219
ConnectError::InvalidUrl(ref msg) => write!(fmt, ": {}", msg),
220+
ConnectError::DbError(ref err) => write!(fmt, ": {}", err),
221+
ConnectError::SslError(ref err) => write!(fmt, ": {}", err),
222+
ConnectError::IoError(ref err) => write!(fmt, ": {}", err),
220223
_ => Ok(())
221224
}
222225
}
@@ -227,14 +230,14 @@ impl error::Error for ConnectError {
227230
match *self {
228231
ConnectError::InvalidUrl(_) => "Invalid URL",
229232
ConnectError::MissingUser => "User missing in URL",
230-
ConnectError::DbError(_) => "An error from the Postgres server itself",
233+
ConnectError::DbError(_) => "Error reported by Postgres",
231234
ConnectError::MissingPassword => "The server requested a password but none was provided",
232235
ConnectError::UnsupportedAuthentication => {
233236
"The server requested an unsupported authentication method"
234237
}
235238
ConnectError::NoSslSupport => "The server does not support SSL",
236239
ConnectError::SslError(_) => "Error initiating SSL session",
237-
ConnectError::IoError(_) => "Error communicating with server",
240+
ConnectError::IoError(_) => "Error communicating with the server",
238241
}
239242
}
240243

@@ -300,7 +303,10 @@ impl fmt::Display for Error {
300303
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
301304
try!(fmt.write_str(error::Error::description(self)));
302305
match *self {
306+
Error::DbError(ref err) => write!(fmt, ": {}", err),
307+
Error::IoError(ref err) => write!(fmt, ": {}", err),
303308
Error::WrongType(ref ty) => write!(fmt, ": saw type {:?}", ty),
309+
Error::Conversion(ref err) => write!(fmt, ": {}", err),
304310
_ => Ok(()),
305311
}
306312
}
@@ -309,11 +315,11 @@ impl fmt::Display for Error {
309315
impl error::Error for Error {
310316
fn description(&self) -> &str {
311317
match *self {
312-
Error::DbError(_) => "An error reported by the Postgres server",
313-
Error::IoError(_) => "An error communicating with the Postgres server",
318+
Error::DbError(_) => "Error reported by Postgres",
319+
Error::IoError(_) => "Error communicating with the server",
314320
Error::WrongType(_) => "Unexpected type",
315321
Error::InvalidColumn => "Invalid column",
316-
Error::Conversion(_) => "An error converting between Postgres and Rust types",
322+
Error::Conversion(_) => "Error converting between Postgres and Rust types",
317323
}
318324
}
319325

0 commit comments

Comments
 (0)