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    /// The codec stored in metadata doesn't match the expected codec.
26    #[error("codec mismatch: expected {expected}, found {found}")]
27    CodecMismatch { expected: String, found: String },
28
29    /// Invalid layout construction or access (vector quantization).
30    #[error("layout error: {detail}")]
31    LayoutError { detail: String },
32
33    /// `ColumnCodec::Auto` reached a point where a concrete codec was required.
34    ///
35    /// `Auto` is a user-facing selection hint that must be resolved to a
36    /// concrete codec at flush time. If `Auto` appears in a serialized
37    /// on-disk header or is passed directly to an encoder, the write path
38    /// has a bug — `ColumnCodec::try_resolve()` was not called.
39    #[error("unresolved Auto codec: codec must be resolved to a concrete variant before writing")]
40    UnresolvedAuto,
41
42    /// A codec name string did not match any canonical form.
43    ///
44    /// Canonical names are lowercase snake_case exactly as returned by
45    /// `ColumnCodec::as_str()`. No case-insensitive matching; no hyphen or
46    /// space variants. The error message lists all valid names.
47    #[error("unknown codec name '{name}'; valid names: {valid}")]
48    UnknownCodec { name: String, valid: &'static str },
49}