Skip to main content

imap_client/
error.rs

1//! Error type for the IMAP client.
2
3use imap_core::error::ParseError;
4use thiserror::Error;
5
6/// Errors returned by [`RawClient`](crate::client::RawClient) and
7/// [`Session`](crate::session::Session) operations.
8#[derive(Error, Debug)]
9pub enum ClientError {
10    /// An underlying socket I/O error.
11    #[error("I/O error: {0}")]
12    Io(#[from] std::io::Error),
13    /// A server response could not be parsed.
14    #[error("Parse error: {0}")]
15    Parse(#[from] ParseError),
16    /// The connection was closed before the operation completed.
17    #[error("Connection closed")]
18    ConnectionClosed,
19    /// A single response frame exceeded the client's in-flight size cap — a
20    /// denial-of-service guard against a server that never terminates a frame.
21    #[error("response frame exceeded the maximum size of {max} bytes")]
22    FrameTooLarge {
23        /// The maximum frame size, in bytes, that the client will buffer.
24        max: usize,
25    },
26    /// The server returned a tagged `NO` / `BAD`; the string is its resp-text.
27    #[error("Command failed: {0}")]
28    CommandFailed(String),
29    /// A command required a capability the server did not advertise.
30    #[error("Capability not supported: {0}")]
31    UnsupportedCapability(&'static str),
32    /// The command did not receive its tagged response within the timeout.
33    #[error("Command timed out")]
34    Timeout,
35}