Skip to main content

nodedb_fts/lsm/segment/
error.rs

1// SPDX-License-Identifier: Apache-2.0
2
3//! Typed errors for segment I/O and validation.
4
5use thiserror::Error;
6
7/// All failure modes for reading or writing an FTS segment file.
8#[derive(Debug, Error)]
9#[non_exhaustive]
10pub enum SegmentError {
11    /// Magic bytes at offset 0..4 do not match `b"FTSS"`.
12    #[error("bad segment magic: expected b\"FTSS\"")]
13    BadMagic,
14
15    /// The segment was written by an incompatible format version.
16    #[error("unsupported segment version {found} (current: {expected})")]
17    UnsupportedVersion { found: u16, expected: u16 },
18
19    /// The footer CRC does not match the re-computed CRC of the preceding bytes.
20    #[error("segment checksum mismatch: expected {expected:#010x}, actual {actual:#010x}")]
21    ChecksumMismatch { expected: u32, actual: u32 },
22
23    /// The file is shorter than the minimum valid segment size.
24    #[error("segment data is truncated")]
25    Truncated,
26
27    /// A term exceeds the maximum encodable length (u16::MAX bytes).
28    #[error("term length {term_len} exceeds maximum {max}")]
29    TermTooLong { term_len: usize, max: usize },
30}