Skip to main content

nodedb_strict/
error.rs

1// SPDX-License-Identifier: Apache-2.0
2
3//! Error types for Binary Tuple encoding/decoding.
4
5use nodedb_types::columnar::ColumnType;
6
7/// Errors from Binary Tuple encoding and decoding.
8#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
9#[non_exhaustive]
10pub enum StrictError {
11    /// Wrong number of values for the schema.
12    #[error("expected {expected} values, got {got}")]
13    ValueCountMismatch { expected: usize, got: usize },
14
15    /// A value's type doesn't match the schema column type.
16    #[error("column '{column}': expected {expected}, got incompatible value")]
17    TypeMismatch {
18        column: String,
19        expected: ColumnType,
20    },
21
22    /// A non-nullable column received a null value with no default.
23    #[error("column '{0}' is NOT NULL and has no default")]
24    NullViolation(String),
25
26    /// Tuple bytes are too short to contain the header.
27    #[error("tuple too short: need at least {expected} bytes, got {got}")]
28    TruncatedTuple { expected: usize, got: usize },
29
30    /// Column index out of range for the schema.
31    #[error("column index {index} out of range (schema has {count} columns)")]
32    ColumnOutOfRange { index: usize, count: usize },
33
34    /// Offset table entry points outside the tuple.
35    #[error("corrupt offset table: offset {offset} exceeds tuple length {len}")]
36    CorruptOffset { offset: u32, len: usize },
37
38    /// Schema version in tuple is newer than the reader's schema.
39    #[error("tuple schema version {tuple_version} is newer than reader version {reader_version}")]
40    NewerSchemaVersion {
41        tuple_version: u16,
42        reader_version: u16,
43    },
44
45    /// Magic bytes at the start of the tuple do not match `MAGIC`.
46    #[error("invalid tuple magic: expected 0x{expected:08X}, got 0x{got:08X}")]
47    InvalidMagic { expected: u32, got: u32 },
48
49    /// Format version byte does not match `FORMAT_VERSION`.
50    #[error("unsupported tuple format version: expected {expected}, got {got}")]
51    InvalidFormatVersion { expected: u8, got: u8 },
52}