Skip to main content

sapphire_framework_session/
error.rs

1//! Error type for the replication session.
2
3/// Errors raised by a session.
4#[derive(Debug, thiserror::Error)]
5pub enum Error {
6    /// Reading or writing the stream failed.
7    #[error("I/O error: {0}")]
8    Io(#[from] std::io::Error),
9    /// A control frame's JSON did not decode, or a message did not encode.
10    #[error("serialization error: {0}")]
11    Codec(#[from] serde_json::Error),
12    /// The peer sent something the framing or the session does not allow.
13    #[error("protocol error: {0}")]
14    Protocol(String),
15    /// A frame announced more payload than [`crate::MAX_FRAME_LEN`].
16    #[error("frame of {len} bytes exceeds the {max}-byte limit")]
17    FrameTooLarge {
18        /// Length the frame announced, in bytes.
19        len: usize,
20        /// Length this build accepts, in bytes.
21        max: usize,
22    },
23    /// The peer speaks a session format this build does not.
24    #[error("session format {theirs} is not the supported {ours}")]
25    VersionMismatch {
26        /// The format this build speaks.
27        ours: u32,
28        /// The format the peer announced.
29        theirs: u32,
30    },
31    /// The replication core failed; the message is its error's `Display`.
32    #[error("replication error: {0}")]
33    Sync(String),
34    /// The peer said it would not continue, and why.
35    #[error("the peer refused the session: {0}")]
36    Refused(String),
37}
38
39/// Result alias for a session.
40pub type Result<T> = std::result::Result<T, Error>;