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 its kind allows: [`crate::MAX_FRAME_LEN`] for a
16 /// control frame, [`crate::CHUNK`] for a content chunk.
17 #[error("frame of {len} bytes exceeds the {max}-byte limit")]
18 FrameTooLarge {
19 /// Length the frame announced, in bytes.
20 len: usize,
21 /// Length this build accepts, in bytes.
22 max: usize,
23 },
24 /// The peer speaks a session format this build does not.
25 #[error("session format {theirs} is not the supported {ours}")]
26 VersionMismatch {
27 /// The format this build speaks.
28 ours: u32,
29 /// The format the peer announced.
30 theirs: u32,
31 },
32 /// The replication core failed; the message is its error's `Display`.
33 #[error("replication error: {0}")]
34 Sync(String),
35 /// The writer is gone — the stream failed under it — so nothing more can be sent.
36 #[error("the stream closed")]
37 Closed,
38 /// The peer said it would not continue, and why.
39 #[error("the peer refused the session: {0}")]
40 Refused(String),
41}
42
43/// Result alias for a session.
44pub type Result<T> = std::result::Result<T, Error>;