Skip to main content

ember_protocol/
error.rs

1//! Protocol error types for RESP3 parsing.
2
3use thiserror::Error;
4
5/// Errors that can occur when parsing the RESP3 wire format.
6#[derive(Debug, Error, Clone, PartialEq, Eq)]
7pub enum ProtocolError {
8    /// The input buffer doesn't contain a complete frame yet.
9    /// The caller should read more data and try again.
10    #[error("incomplete frame: need more data")]
11    Incomplete,
12
13    /// Reached end of input unexpectedly while parsing a frame.
14    #[error("unexpected end of input")]
15    UnexpectedEof,
16
17    /// The first byte of a frame didn't match any known RESP3 type prefix.
18    #[error("invalid type prefix: {0:#04x}")]
19    InvalidPrefix(u8),
20
21    /// Failed to parse an integer value from the frame content.
22    #[error("invalid integer encoding")]
23    InvalidInteger,
24
25    /// A bulk string or array declared an invalid length (e.g. negative).
26    #[error("invalid frame length: {0}")]
27    InvalidFrameLength(i64),
28
29    /// Expected an array frame for a command, but got something else.
30    #[error("invalid command frame: {0}")]
31    InvalidCommandFrame(String),
32
33    /// Command received with the wrong number of arguments.
34    #[error("wrong number of arguments for '{0}' command")]
35    WrongArity(String),
36
37    /// The frame exceeds the maximum nesting depth.
38    #[error("frame nesting depth exceeds limit of {0}")]
39    NestingTooDeep(usize),
40
41    /// An array or map declares more elements than the allowed maximum.
42    #[error("array/map element count {0} exceeds limit")]
43    TooManyElements(usize),
44
45    /// A bulk string exceeds the maximum allowed length.
46    #[error("bulk string length {0} exceeds limit")]
47    BulkStringTooLarge(usize),
48}