Skip to main content

kacrab_protocol/tagged/
error.rs

1//! Error types for [`crate::tagged`].
2
3use crate::primitives::PrimitiveError;
4
5/// Error from tagged-field section read/write.
6#[derive(Debug, thiserror::Error)]
7#[non_exhaustive]
8pub enum TaggedFieldError {
9    /// Underlying primitive read failed (varint count / tag / size).
10    #[error(transparent)]
11    Primitive(#[from] PrimitiveError),
12
13    /// Tag numbers were not strictly ascending.
14    #[error("tagged fields out of order: tag {tag} after tag {prev_tag}")]
15    OutOfOrder {
16        /// The tag that violated the order.
17        tag: u32,
18        /// The previous (greater-or-equal) tag.
19        prev_tag: u32,
20    },
21
22    /// Declared field size exceeds the remaining buffer.
23    #[error("tagged field {tag} size {size} exceeds remaining {remaining}")]
24    SizeOverflow {
25        /// The tag whose size was bad.
26        tag: u32,
27        /// Declared size.
28        size: usize,
29        /// Bytes actually remaining in the buffer.
30        remaining: usize,
31    },
32
33    /// A tagged-field count does not fit this platform's address space.
34    #[error("tagged field count {count} exceeds maximum {max}")]
35    CountOverflow {
36        /// Declared count.
37        count: u32,
38        /// Maximum representable count on this platform.
39        max: usize,
40    },
41
42    /// A tagged-field payload is too large for the Kafka varint size prefix.
43    #[error("tagged field {tag} size {size} exceeds maximum {max}")]
44    FieldTooLarge {
45        /// The tag whose payload is too large.
46        tag: u32,
47        /// Payload size.
48        size: usize,
49        /// Maximum encodable payload size.
50        max: usize,
51    },
52}