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