kacrab_protocol/bytes_io/
error.rs1use crate::primitives::PrimitiveError;
4
5#[derive(Debug, thiserror::Error)]
7#[error("Kafka bytes codec failed")]
8#[non_exhaustive]
9pub struct BytesError {
10 #[source]
12 pub kind: BytesErrorKind,
13}
14
15impl BytesError {
16 #[must_use]
18 pub const fn new(kind: BytesErrorKind) -> Self {
19 Self { kind }
20 }
21}
22
23impl From<BytesErrorKind> for BytesError {
24 fn from(kind: BytesErrorKind) -> Self {
25 Self::new(kind)
26 }
27}
28
29impl From<PrimitiveError> for BytesError {
30 fn from(err: PrimitiveError) -> Self {
31 Self::new(BytesErrorKind::Primitive(err))
32 }
33}
34
35#[derive(Debug, thiserror::Error)]
37#[non_exhaustive]
38pub enum BytesErrorKind {
39 #[error(transparent)]
41 Primitive(#[from] PrimitiveError),
42
43 #[error("non-nullable bytes has null marker; use the nullable variant")]
45 UnexpectedNull,
46
47 #[error("negative length {length} on non-nullable bytes")]
49 NegativeLength {
50 length: i32,
52 },
53
54 #[error("bytes length {length} exceeds maximum {max}")]
56 TooLong {
57 length: usize,
60 max: usize,
62 },
63}