respite/
error.rs

1use thiserror::Error;
2
3/// An error encountered while reading a RESP stream.
4#[derive(Debug, Error)]
5#[non_exhaustive]
6pub enum RespError {
7    /// Reached the end of the stream unexpectedly
8    #[error("unexpected end of input")]
9    EndOfInput,
10
11    /// Received an invalid boolean
12    #[error("invalid boolean")]
13    InvalidBoolean,
14
15    /// Received an invalid blob
16    #[error("invalid blob length")]
17    InvalidBlobLength,
18
19    /// Received an invalid double
20    #[error("invalid double")]
21    InvalidDouble,
22
23    /// Received an invalid integer
24    #[error("invalid integer")]
25    InvalidInteger,
26
27    /// Received an invalid map
28    #[error("invalid map")]
29    InvalidMap,
30
31    /// Received an invalid set
32    #[error("invalid set")]
33    InvalidSet,
34
35    /// Received an invalid verbatim
36    #[error("invalid verbatim")]
37    InvalidVerbatim,
38
39    /// Error reading from the stream.
40    #[error("io error")]
41    IO(#[from] std::io::Error),
42
43    /// Simple frame cannot contain a newline.
44    #[error("newline is not allowed in this frame")]
45    Newline,
46
47    /// Unsupported in current version.
48    #[error("unsupported in the current version")]
49    Version,
50
51    /// Expected a primitive, but got a complex value
52    #[error("map keys and set values must be primitives")]
53    RespPrimitive,
54
55    /// Received an inline request that was too big.
56    #[error("too big inline request")]
57    TooBigInline,
58
59    /// Unexpected byte sequence
60    #[error("expected {:?}, got {:?}", char::from(*.0), char::from(*.1))]
61    Unexpected(u8, u8),
62
63    /// Unknown RESP type
64    #[error("unknown resp type: {:?}", char::from(*.0))]
65    UnknownType(u8),
66
67    /// Invalid inline command
68    #[error("invalid inline command")]
69    InvalidInline,
70}