1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//! Top-level error type for the `dyniak` crate.
use dynomite::embed::DatastoreError;
/// Errors produced by the `dyniak` protocol layer.
///
/// The variants cover wire-level failures (framing, decode, encode),
/// protocol-level failures (unknown message code), and downstream
/// failures from the [`dynomite::embed::Datastore`] handed to
/// [`crate::server::serve_pbc`].
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum RiakError {
/// Underlying socket I/O failure.
#[error("io: {0}")]
Io(#[from] std::io::Error),
/// The peer announced a frame longer than the configured maximum.
/// Used as a hard cap so a malicious peer cannot pin arbitrary
/// memory by claiming a multi-gigabyte frame.
#[error("frame too large: announced {announced} bytes, maximum {max} bytes")]
FrameTooLarge {
/// Length the peer claimed (excluding the 4-byte length prefix).
announced: u32,
/// Configured maximum frame length.
max: u32,
},
/// The peer announced a frame of length zero, which is illegal:
/// every PBC frame must include at least the 1-byte message code.
#[error("empty frame: zero-length PBC frames are not allowed")]
EmptyFrame,
/// Connection was closed by the peer mid-frame.
#[error("connection closed mid-frame ({read} of {expected} bytes read)")]
UnexpectedEof {
/// Bytes already drained from the socket.
read: usize,
/// Bytes the framer was waiting on.
expected: usize,
},
/// The peer sent a message code outside the supported set.
#[error("unknown PBC message code: {0}")]
UnknownMessageCode(u8),
/// `prost` failed to decode the message body.
#[error("protobuf decode: {0}")]
Decode(#[from] prost::DecodeError),
/// `prost` failed to encode the response body.
#[error("protobuf encode: {0}")]
Encode(#[from] prost::EncodeError),
/// The downstream datastore returned an error.
#[error("datastore: {0}")]
Datastore(#[from] DatastoreError),
}