Skip to main content

kacrab_protocol/uuid/
error.rs

1//! Error types for [`crate::uuid`].
2//!
3//! Each variant already carries enough context (length, error string) on its
4//! own, so this is a flat enum rather than the `struct + Kind` shape used by
5//! modules with cross-variant context (e.g. [`crate::record`]).
6
7/// Error from [`crate::uuid::KafkaUuid`] parsing or generation.
8#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
9#[non_exhaustive]
10pub enum UuidError {
11    /// Input string is longer than the maximum base64 representation.
12    #[error("input string too long ({length} chars, max {max})")]
13    StringTooLong {
14        /// Length of the input string.
15        length: usize,
16        /// Maximum allowed length.
17        max: usize,
18    },
19
20    /// Base64 decoding failed.
21    #[error("invalid base64: {message}")]
22    InvalidBase64 {
23        /// Underlying error message from the base64 decoder.
24        message: String,
25    },
26
27    /// Decoded byte length does not match the UUID size.
28    #[error("decoded {actual} bytes, expected {expected}")]
29    InvalidLength {
30        /// Expected byte length (16).
31        expected: usize,
32        /// Actual decoded byte length.
33        actual: usize,
34    },
35
36    /// `random()` exhausted its retry budget.
37    #[error("random UUID generation exhausted {retries} retries")]
38    RandomExhausted {
39        /// Number of attempts made before giving up.
40        retries: u32,
41    },
42}