Skip to main content

nodedb_codec/
error.rs

1// SPDX-License-Identifier: Apache-2.0
2
3//! Error types for codec operations.
4
5/// Errors that can occur during encoding or decoding.
6#[derive(Debug, thiserror::Error)]
7#[non_exhaustive]
8pub enum CodecError {
9    /// Input data is too short or truncated.
10    #[error("truncated input: expected at least {expected} bytes, got {actual}")]
11    Truncated { expected: usize, actual: usize },
12
13    /// Input data is corrupted (invalid header, bad checksum, etc.).
14    #[error("corrupt data: {detail}")]
15    Corrupt { detail: String },
16
17    /// Decompression failed (LZ4/Zstd library error).
18    #[error("decompression failed: {detail}")]
19    DecompressFailed { detail: String },
20
21    /// Compression failed (LZ4/Zstd library error).
22    #[error("compression failed: {detail}")]
23    CompressFailed { detail: String },
24
25    /// A decoded resource declaration exceeds the application's hard limit.
26    #[error("resource limit exceeded for {resource}: requested {requested} bytes, limit {limit}")]
27    ResourceLimit {
28        resource: String,
29        requested: usize,
30        limit: usize,
31    },
32
33    /// The codec stored in metadata doesn't match the expected codec.
34    #[error("codec mismatch: expected {expected}, found {found}")]
35    CodecMismatch { expected: String, found: String },
36
37    /// Invalid layout construction or access (vector quantization).
38    #[error("layout error: {detail}")]
39    LayoutError { detail: String },
40
41    /// `ColumnCodec::Auto` reached a point where a concrete codec was required.
42    ///
43    /// `Auto` is a user-facing selection hint that must be resolved to a
44    /// concrete codec at flush time. If `Auto` appears in a serialized
45    /// on-disk header or is passed directly to an encoder, the write path
46    /// has a bug — `ColumnCodec::try_resolve()` was not called.
47    #[error("unresolved Auto codec: codec must be resolved to a concrete variant before writing")]
48    UnresolvedAuto,
49
50    /// A codec name string did not match any canonical form.
51    ///
52    /// Canonical names are lowercase snake_case exactly as returned by
53    /// `ColumnCodec::as_str()`. No case-insensitive matching; no hyphen or
54    /// space variants. The error message lists all valid names.
55    #[error("unknown codec name '{name}'; valid names: {valid}")]
56    UnknownCodec { name: String, valid: &'static str },
57}