Skip to main content

relaygate_protocol/
error.rs

1/// Failures raised while encoding or decoding an SDK–Gateway frame.
2#[derive(Debug, thiserror::Error)]
3pub enum ProtocolError {
4    /// The underlying transport failed while a frame was being read or written.
5    #[error("frame I/O failed: {0}")]
6    Io(#[from] std::io::Error),
7    /// A frame payload is longer than the codec's configured maximum.
8    #[error("frame length {actual} exceeds configured maximum {maximum}")]
9    FrameTooLarge {
10        /// Payload length seen on the wire, in bytes.
11        actual: usize,
12        /// Configured payload limit, in bytes.
13        maximum: usize,
14    },
15    /// The frame header names a protocol version this codec does not implement.
16    #[error("unsupported protocol version {0}")]
17    UnsupportedVersion(u8),
18    /// The frame header does not begin with the expected magic bytes.
19    #[error("invalid frame magic")]
20    InvalidMagic,
21    /// The header kind byte does not name a frame in this protocol version.
22    #[error("unknown frame kind {0}")]
23    UnknownFrameKind(u8),
24    /// A byte-valued enum field carries a value outside the contract.
25    #[error("unknown enum value {value} for {name}")]
26    UnknownEnum {
27        /// Name of the enum type that rejected the value.
28        name: &'static str,
29        /// The wire byte that matched no variant.
30        value: u8,
31    },
32    /// The payload ended before the named field was complete.
33    #[error("truncated {0}")]
34    Truncated(&'static str),
35    /// The named string field is not valid UTF-8.
36    #[error("invalid UTF-8 in {0}")]
37    InvalidUtf8(&'static str),
38    /// The decoded namespace and name do not form a valid `Destination`.
39    #[error("invalid Destination")]
40    InvalidDestination,
41    /// A length-prefixed field is longer than the wire format allows.
42    #[error("{field} is too long: {actual} bytes, maximum {maximum}")]
43    FieldTooLong {
44        /// Name of the field that exceeded its limit.
45        field: &'static str,
46        /// Length of the offered value, in bytes.
47        actual: usize,
48        /// Largest length the field accepts, in bytes.
49        maximum: usize,
50    },
51    /// The payload held bytes left over after the frame was decoded.
52    #[error("frame has {0} trailing bytes")]
53    TrailingBytes(usize),
54    /// A frame length cannot be represented on the wire, or a decode offset
55    /// would overflow.
56    #[error("frame length cannot be represented on the wire")]
57    LengthOverflow,
58}