use crate::primitives::PrimitiveError;
#[derive(Debug, thiserror::Error)]
#[error("Kafka bytes codec failed")]
#[non_exhaustive]
pub struct BytesError {
#[source]
pub kind: BytesErrorKind,
}
impl BytesError {
#[must_use]
pub const fn new(kind: BytesErrorKind) -> Self {
Self { kind }
}
}
impl From<BytesErrorKind> for BytesError {
fn from(kind: BytesErrorKind) -> Self {
Self::new(kind)
}
}
impl From<PrimitiveError> for BytesError {
fn from(err: PrimitiveError) -> Self {
Self::new(BytesErrorKind::Primitive(err))
}
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum BytesErrorKind {
#[error(transparent)]
Primitive(#[from] PrimitiveError),
#[error("non-nullable bytes has null marker; use the nullable variant")]
UnexpectedNull,
#[error("negative length {length} on non-nullable bytes")]
NegativeLength {
length: i32,
},
#[error("bytes length {length} exceeds maximum {max}")]
TooLong {
length: usize,
max: usize,
},
}