From ff87e4c595d2ed62b3e9a8f397653d3ef3a5820b Mon Sep 17 00:00:00 2001 From: Alexis Mousset Date: Sat, 17 Jun 2017 18:06:47 +0200 Subject: [PATCH] feat(transport): Improve description of all transport error types --- lettre/src/file/error.rs | 7 ++++--- lettre/src/sendmail/error.rs | 4 ++-- lettre/src/smtp/error.rs | 20 +++++++++++--------- lettre/src/smtp/mod.rs | 2 +- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/lettre/src/file/error.rs b/lettre/src/file/error.rs index ab1b2b0..8283e0a 100644 --- a/lettre/src/file/error.rs +++ b/lettre/src/file/error.rs @@ -27,15 +27,16 @@ impl Display for Error { impl StdError for Error { fn description(&self) -> &str { match *self { - Client(_) => "an unknown error occured", - Io(_) => "an I/O error occured", - JsonSerialization(_) => "a JSON serialization error occured", + Client(err) => err, + Io(ref err) => err.description(), + JsonSerialization(ref err) => err.description(), } } fn cause(&self) -> Option<&StdError> { match *self { Io(ref err) => Some(&*err as &StdError), + JsonSerialization(ref err) => Some(&*err as &StdError), _ => None, } } diff --git a/lettre/src/sendmail/error.rs b/lettre/src/sendmail/error.rs index d3dab39..98c7d83 100644 --- a/lettre/src/sendmail/error.rs +++ b/lettre/src/sendmail/error.rs @@ -25,8 +25,8 @@ impl Display for Error { impl StdError for Error { fn description(&self) -> &str { match *self { - Client(_) => "an unknown error occured", - Io(_) => "an I/O error occured", + Client(err) => err, + Io(ref err) => err.description(), } } diff --git a/lettre/src/smtp/error.rs b/lettre/src/smtp/error.rs index 04768d6..556e67b 100644 --- a/lettre/src/smtp/error.rs +++ b/lettre/src/smtp/error.rs @@ -46,29 +46,31 @@ impl StdError for Error { match *self { // Try to display the first line of the server's response that usually // contains a short humanly readable error message - Transient(ref e) => { - match e.first_line() { + Transient(ref err) => { + match err.first_line() { Some(line) => line, None => "undetailed transient error during SMTP transaction", } } - Permanent(ref e) => { - match e.first_line() { + Permanent(ref err) => { + match err.first_line() { Some(line) => line, None => "undetailed permanent error during SMTP transaction", } } - ResponseParsing(e) => e, - ChallengeParsing(ref e) => e.description(), - Utf8Parsing(ref e) => e.description(), + ResponseParsing(err) => err, + ChallengeParsing(ref err) => err.description(), + Utf8Parsing(ref err) => err.description(), Resolution => "could not resolve hostname", - Client(e) => e, - Io(ref e) => e.description(), + Client(err) => err, + Io(ref err) => err.description(), } } fn cause(&self) -> Option<&StdError> { match *self { + ChallengeParsing(ref err) => Some(&*err as &StdError), + Utf8Parsing(ref err) => Some(&*err as &StdError), Io(ref err) => Some(&*err as &StdError), _ => None, } diff --git a/lettre/src/smtp/mod.rs b/lettre/src/smtp/mod.rs index 1760d7a..d927011 100644 --- a/lettre/src/smtp/mod.rs +++ b/lettre/src/smtp/mod.rs @@ -215,7 +215,7 @@ impl SmtpTransportBuilder { timeout: Some(Duration::new(60, 0)), }) } - None => Err(From::from("Could not resolve hostname")), + None => Err(Error::Resolution), } }