Skip to main content

shuflr_wire/
error.rs

1//! Typed errors for the wire codec.
2//!
3//! Decode errors fall into two classes: *framing* errors (bad magic,
4//! bad xxh3, unknown kind) that indicate an incompatible / corrupt
5//! peer and warrant closing the connection; *insufficient* (which is
6//! not actually an Err, represented as Ok(None) by the decoder) for
7//! when we simply haven't read enough bytes yet.
8
9use thiserror::Error;
10
11#[derive(Debug, Error)]
12pub enum WireError {
13    #[error("unsupported magic: got {got:?}, expected SHUFLRW1")]
14    BadMagic { got: [u8; 8] },
15
16    #[error("unsupported protocol version {got}; this codec speaks version 1")]
17    BadVersion { got: u8 },
18
19    #[error("message kind {got} is not recognized in v1")]
20    UnknownKind { got: u8 },
21
22    #[error("xxh3 mismatch on kind={kind}: wire={wire:016x}, computed={computed:016x}")]
23    Xxh3Mismatch { kind: u8, wire: u64, computed: u64 },
24
25    #[error("message payload length {got} exceeds MAX_MESSAGE_BYTES ({max})")]
26    PayloadTooLarge { got: u32, max: u32 },
27
28    #[error("truncated payload for kind={kind}: expected {expected} bytes, got {got}")]
29    TruncatedPayload {
30        kind: u8,
31        expected: usize,
32        got: usize,
33    },
34
35    #[error("malformed field in kind={kind}: {detail}")]
36    Malformed { kind: u8, detail: String },
37}