Skip to main content

ssz/
error.rs

1//! Errors during SSZ decoding.
2
3/// Errors encountered while decoding an SSZ-encoded byte slice.
4#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
5pub enum DecodeError {
6    /// Input ended before the entire value could be read.
7    #[error("unexpected end of input (expected {expected} bytes, got {actual})")]
8    UnexpectedEof { expected: usize, actual: usize },
9
10    /// Input contained more bytes than the expected value occupies.
11    #[error("trailing bytes after value (expected {expected} bytes, got {actual})")]
12    TrailingBytes { expected: usize, actual: usize },
13
14    /// A length offset pointed outside the input slice or below the fixed region.
15    #[error("invalid offset {offset} (data length {len}, fixed region {fixed})")]
16    InvalidOffset {
17        offset: usize,
18        len: usize,
19        fixed: usize,
20    },
21
22    /// Offsets must be monotonically non-decreasing.
23    #[error("offsets not monotonic: {prev} > {curr}")]
24    OffsetsNotMonotonic { prev: usize, curr: usize },
25
26    /// A variable-length object exceeded its compile-time cap.
27    #[error("list length {len} exceeds bound {bound}")]
28    BoundExceeded { len: u64, bound: u64 },
29
30    /// A fixed-length vector was given the wrong number of elements.
31    #[error("fixed vector length mismatch (expected {expected}, got {actual})")]
32    LengthMismatch { expected: usize, actual: usize },
33
34    /// Union/Option selector outside the allowed range.
35    #[error("invalid selector byte {0}")]
36    InvalidSelector(u8),
37
38    /// Bool byte was not 0 or 1.
39    #[error("invalid bool byte {0}")]
40    InvalidBool(u8),
41
42    /// Bitlist sentinel `1` bit was missing.
43    #[error("bitlist missing trailing sentinel bit")]
44    MissingBitlistSentinel,
45
46    /// Bitvector/Bitlist contained set bits beyond the declared length.
47    #[error("excess bits set beyond declared length")]
48    ExcessBits,
49
50    /// Sorted-collection keys were not strictly ascending.
51    #[error("keys not in strictly ascending order")]
52    NotSorted,
53
54    /// `NonZeroU32` decoded as zero.
55    #[error("expected NonZeroU32 but got 0")]
56    ZeroNonZero,
57
58    /// Custom decode error from a user implementation.
59    #[error("custom decode error: {0}")]
60    Custom(&'static str),
61}