Promote Unexpected error from ParseError to Error.

This commit is contained in:
Todd Mortimer 2021-04-19 20:39:59 -04:00
parent 08de3362b4
commit 1cabb3bb56
2 changed files with 8 additions and 6 deletions

View file

@ -21,7 +21,7 @@ default = ["tls"]
native-tls = { version = "0.2.2", optional = true } native-tls = { version = "0.2.2", optional = true }
regex = "1.0" regex = "1.0"
bufstream = "0.1" bufstream = "0.1"
imap-proto = "0.14.0" imap-proto = "0.14.1"
nom = "6.0" nom = "6.0"
base64 = "0.13" base64 = "0.13"
chrono = "0.4" chrono = "0.4"

View file

@ -76,6 +76,10 @@ pub enum Error {
Validate(ValidateError), Validate(ValidateError),
/// Error appending an e-mail. /// Error appending an e-mail.
Append, Append,
/// An unexpected response was received. This could be a response from a command,
/// or an unsolicited response that could not be converted into a local type in
/// [`UnsolicitedResponse`].
Unexpected(Response<'static>),
} }
impl From<IoError> for Error { impl From<IoError> for Error {
@ -112,7 +116,7 @@ impl From<TlsError> for Error {
impl<'a> From<Response<'a>> for Error { impl<'a> From<Response<'a>> for Error {
fn from(err: Response<'a>) -> Error { fn from(err: Response<'a>) -> Error {
Error::Parse(ParseError::Unexpected(format!("{:?}", err))) Error::Unexpected(err.into_owned())
} }
} }
@ -130,6 +134,7 @@ impl fmt::Display for Error {
Error::Bad(ref data) => write!(f, "Bad Response: {}", data), Error::Bad(ref data) => write!(f, "Bad Response: {}", data),
Error::ConnectionLost => f.write_str("Connection Lost"), Error::ConnectionLost => f.write_str("Connection Lost"),
Error::Append => f.write_str("Could not append mail to mailbox"), Error::Append => f.write_str("Could not append mail to mailbox"),
Error::Unexpected(ref r) => write!(f, "Unexpected Response: {:?}", r),
} }
} }
} }
@ -149,6 +154,7 @@ impl StdError for Error {
Error::No(_) => "No Response", Error::No(_) => "No Response",
Error::ConnectionLost => "Connection lost", Error::ConnectionLost => "Connection lost",
Error::Append => "Could not append mail to mailbox", Error::Append => "Could not append mail to mailbox",
Error::Unexpected(_) => "Unexpected Response",
} }
} }
@ -170,8 +176,6 @@ impl StdError for Error {
pub enum ParseError { pub enum ParseError {
/// Indicates an error parsing the status response. Such as OK, NO, and BAD. /// Indicates an error parsing the status response. Such as OK, NO, and BAD.
Invalid(Vec<u8>), Invalid(Vec<u8>),
/// An unexpected response was encountered.
Unexpected(String),
/// The client could not find or decode the server's authentication challenge. /// The client could not find or decode the server's authentication challenge.
Authentication(String, Option<DecodeError>), Authentication(String, Option<DecodeError>),
/// The client received data that was not UTF-8 encoded. /// The client received data that was not UTF-8 encoded.
@ -182,7 +186,6 @@ impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self { match *self {
ParseError::Invalid(_) => f.write_str("Unable to parse status response"), ParseError::Invalid(_) => f.write_str("Unable to parse status response"),
ParseError::Unexpected(_) => f.write_str("Encountered unexpected parse response"),
ParseError::Authentication(_, _) => { ParseError::Authentication(_, _) => {
f.write_str("Unable to parse authentication response") f.write_str("Unable to parse authentication response")
} }
@ -195,7 +198,6 @@ impl StdError for ParseError {
fn description(&self) -> &str { fn description(&self) -> &str {
match *self { match *self {
ParseError::Invalid(_) => "Unable to parse status response", ParseError::Invalid(_) => "Unable to parse status response",
ParseError::Unexpected(_) => "Encountered unexpected parsed response",
ParseError::Authentication(_, _) => "Unable to parse authentication response", ParseError::Authentication(_, _) => "Unable to parse authentication response",
ParseError::DataNotUtf8(_, _) => "Unable to parse data as UTF-8 text", ParseError::DataNotUtf8(_, _) => "Unable to parse data as UTF-8 text",
} }