kacrab_protocol/string/
error.rs1use crate::primitives::PrimitiveError;
4
5#[derive(Debug, thiserror::Error)]
7#[error("kafka string codec failed")]
8#[non_exhaustive]
9pub struct StringError {
10 #[source]
12 pub kind: StringErrorKind,
13}
14
15impl StringError {
16 #[must_use]
18 pub const fn new(kind: StringErrorKind) -> Self {
19 Self { kind }
20 }
21}
22
23impl From<StringErrorKind> for StringError {
24 fn from(kind: StringErrorKind) -> Self {
25 Self::new(kind)
26 }
27}
28
29impl From<PrimitiveError> for StringError {
30 fn from(err: PrimitiveError) -> Self {
31 Self::new(StringErrorKind::Primitive(err))
32 }
33}
34
35#[derive(Debug, thiserror::Error)]
37#[non_exhaustive]
38pub enum StringErrorKind {
39 #[error(transparent)]
41 Primitive(#[from] PrimitiveError),
42
43 #[error("invalid UTF-8 string: {source}")]
45 InvalidUtf8 {
46 #[source]
48 source: std::str::Utf8Error,
49 },
50
51 #[error("non-nullable string has null marker; use the nullable variant")]
53 UnexpectedNull,
54
55 #[error("negative length {length} on non-nullable string")]
57 NegativeLength {
58 length: i32,
60 },
61
62 #[error("string length {length} exceeds maximum {max}")]
64 TooLong {
65 length: usize,
68 max: usize,
70 },
71}