kacrab_protocol/frame/
error.rs1use crate::primitives::PrimitiveError;
4
5#[derive(Debug, thiserror::Error)]
7#[error("kafka frame codec failed")]
8#[non_exhaustive]
9pub struct FrameError {
10 #[source]
12 pub kind: FrameErrorKind,
13}
14
15impl FrameError {
16 #[must_use]
18 pub const fn new(kind: FrameErrorKind) -> Self {
19 Self { kind }
20 }
21}
22
23impl From<FrameErrorKind> for FrameError {
24 fn from(kind: FrameErrorKind) -> Self {
25 Self::new(kind)
26 }
27}
28
29impl From<PrimitiveError> for FrameError {
30 fn from(err: PrimitiveError) -> Self {
31 Self::new(FrameErrorKind::Primitive(err))
32 }
33}
34
35#[derive(Debug, thiserror::Error)]
37#[non_exhaustive]
38pub enum FrameErrorKind {
39 #[error(transparent)]
41 Primitive(#[from] PrimitiveError),
42
43 #[error("negative frame length: {length}")]
45 NegativeLength {
46 length: i32,
48 },
49
50 #[error("frame length {length} exceeds maximum {max}")]
52 TooLarge {
53 length: i32,
55 max: i32,
57 },
58
59 #[error("frame truncated: needed {needed} bytes, only {available} available")]
61 Truncated {
62 needed: usize,
64 available: usize,
66 },
67}