From 809ecbbd07b2af770bd9e03e73524b60468c4063 Mon Sep 17 00:00:00 2001 From: Alexis Mousset Date: Mon, 10 Nov 2014 01:01:12 +0100 Subject: [PATCH] Start documenting the error module --- examples/client.rs | 1 - src/error.rs | 31 ++++++++++++++++--------------- src/extension.rs | 2 -- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/examples/client.rs b/examples/client.rs index caa091b..0cd7430 100644 --- a/examples/client.rs +++ b/examples/client.rs @@ -61,7 +61,6 @@ fn main() { optopt("s", "server", "set the server to use, default is localhost", "SERVER"), optopt("m", "my-hostname", "set the hostname used by the client", "MY_HOSTNAME"), optflag("h", "help", "print this help menu"), - optflag("v", "verbose", "display the transaction details"), ]; let matches = match getopts(args_string.tail(), opts) { diff --git a/src/error.rs b/src/error.rs index 719f15d..d97b9f0 100644 --- a/src/error.rs +++ b/src/error.rs @@ -18,28 +18,31 @@ use response::Response; /// An enum of all error kinds. #[deriving(PartialEq, Eq, Clone, Show)] pub enum ErrorKind { - /// TODO + /// Transient error + /// + /// 4xx reply code TransientError(Response), - /// TODO + /// permanent error + /// + /// 5xx reply code PermanentError(Response), - /// TODO + /// Unknown error UnknownError(String), - /// TODO + /// IO error InternalIoError(IoError), } -/// TODO +/// smtp error type #[deriving(PartialEq, Eq, Clone, Show)] pub struct SmtpError { - /// TODO + /// Error kind pub kind: ErrorKind, - /// TODO + /// Error description pub desc: &'static str, - /// TODO + /// Error cause pub detail: Option, } - impl FromError for SmtpError { fn from_error(err: IoError) -> SmtpError { SmtpError { @@ -94,10 +97,8 @@ impl FromError<&'static str> for SmtpError { impl Error for SmtpError { fn description(&self) -> &str { match self.kind { - TransientError(_) => "a permanent error occured during the SMTP transaction", - PermanentError(_) => "a permanent error occured during the SMTP transaction", - UnknownError(_) => "an unknown error occured during the SMTP transaction", - InternalIoError(_) => "an I/O error occurred", + InternalIoError(ref err) => err.desc, + _ => self.desc, } } @@ -106,7 +107,7 @@ impl Error for SmtpError { TransientError(ref response) => Some(response.to_string()), PermanentError(ref response) => Some(response.to_string()), UnknownError(ref string) => Some(string.to_string()), - _ => None, + InternalIoError(ref err) => err.detail.clone(), } } @@ -118,5 +119,5 @@ impl Error for SmtpError { } } -/// Library generic result type +/// smtp result type pub type SmtpResult = Result; diff --git a/src/extension.rs b/src/extension.rs index 9ee672d..4baac3c 100644 --- a/src/extension.rs +++ b/src/extension.rs @@ -84,8 +84,6 @@ impl Extension { } /// Parses supported ESMTP features - /// - /// TODO: Improve parsing, check RFC pub fn parse_esmtp_response(message: &str) -> Option> { let mut esmtp_features = Vec::new(); for line in message.split_str(CRLF) {