kevy_resp/error.rs
1//! Protocol-level parsing error shared by request + reply parsers,
2//! plus the command-layer error frame type.
3
4/// Why a buffer could not (yet) be parsed into a command (or reply).
5#[derive(Debug, PartialEq, Eq)]
6pub enum ProtocolError {
7 /// A malformed frame that can never become valid (e.g. bad length prefix).
8 Malformed(&'static str),
9}
10
11/// A command-layer error destined for the wire as a RESP error frame.
12///
13/// Carries the complete, already-prefixed message text (`ERR …` /
14/// `WRONGTYPE …` / `INDEXBUILDING …`); the dispatch layer encodes it
15/// verbatim into a `-<text>\r\n` reply. The dedicated type keeps parse
16/// and dispatch helpers from using bare `&'static str` as an error
17/// currency.
18#[derive(Debug, Clone, Copy, PartialEq, Eq)]
19pub enum CmdError {
20 /// The complete wire message for the error frame.
21 Wire(&'static str),
22}
23
24impl CmdError {
25 /// The wire text encoded into the RESP error frame.
26 pub fn as_wire(self) -> &'static str {
27 match self {
28 Self::Wire(s) => s,
29 }
30 }
31}
32
33impl std::fmt::Display for CmdError {
34 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
35 f.write_str(self.as_wire())
36 }
37}
38
39impl std::error::Error for CmdError {}
40
41impl From<&'static str> for CmdError {
42 fn from(s: &'static str) -> Self {
43 Self::Wire(s)
44 }
45}