-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor tag assertion to FatalError check & Fix unexpected increase of tag #231
Changes from all commits
2fca66f
2e9fd1c
ef7779f
3ca8527
6886d4d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,6 +104,8 @@ pub enum Error { | |
/// In response to a STATUS command, the server sent OK without actually sending any STATUS | ||
/// responses first. | ||
MissingStatusResponse, | ||
/// Tag mismatch between client and server. New session must be created. | ||
TagCorrupted(TagCorrupted), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the name |
||
} | ||
|
||
impl From<IoError> for Error { | ||
|
@@ -170,6 +172,7 @@ impl fmt::Display for Error { | |
Error::Append => f.write_str("Could not append mail to mailbox"), | ||
Error::Unexpected(ref r) => write!(f, "Unexpected Response: {:?}", r), | ||
Error::MissingStatusResponse => write!(f, "Missing STATUS Response"), | ||
Error::TagCorrupted(ref data) => write!(f, "Mismatched Tag: {:?}", data), | ||
} | ||
} | ||
} | ||
|
@@ -194,6 +197,7 @@ impl StdError for Error { | |
Error::Append => "Could not append mail to mailbox", | ||
Error::Unexpected(_) => "Unexpected Response", | ||
Error::MissingStatusResponse => "Missing STATUS Response", | ||
Error::TagCorrupted(ref e) => e.description(), | ||
} | ||
} | ||
|
||
|
@@ -207,6 +211,7 @@ impl StdError for Error { | |
#[cfg(feature = "native-tls")] | ||
Error::TlsHandshake(ref e) => Some(e), | ||
Error::Parse(ParseError::DataNotUtf8(_, ref e)) => Some(e), | ||
Error::TagCorrupted(ref e) => Some(e), | ||
_ => None, | ||
} | ||
} | ||
|
@@ -285,6 +290,36 @@ impl StdError for ValidateError { | |
} | ||
} | ||
|
||
/// Tag was corrupted during session. | ||
#[derive(Debug)] | ||
#[non_exhaustive] | ||
pub struct TagCorrupted { | ||
/// Expected tag number | ||
pub(crate) expect: u32, | ||
/// Actual tag number, 0 if parse failed | ||
pub(crate) actual: u32, | ||
} | ||
|
||
impl fmt::Display for TagCorrupted { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!( | ||
f, | ||
"Expected tag number is {}, actual {}", | ||
self.expect, self.actual | ||
) | ||
} | ||
} | ||
|
||
impl StdError for TagCorrupted { | ||
fn description(&self) -> &str { | ||
"Tag is corrupted, session is in an inconsistent state" | ||
} | ||
|
||
fn cause(&self) -> Option<&dyn StdError> { | ||
None | ||
} | ||
Comment on lines
+314
to
+320
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can skip both of these |
||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following the discussion in #229, I'm okay with this change, though I think we should also add a
skip_tag
method toClient
to allow manually incrementing the tag.