Skip to main content

poly_kv/
error.rs

1use thiserror::Error;
2
3/// Errors for the poly-kv crate.
4#[derive(Error, Debug)]
5pub enum PolyKvError {
6    #[error("shape validation failed: {0}")]
7    InvalidShape(String),
8
9    #[error("policy validation failed: {0}")]
10    InvalidPolicy(String),
11
12    #[error("manifest validation failed: {0}")]
13    InvalidManifest(String),
14
15    #[error("receipt validation failed: {0}")]
16    InvalidReceipt(String),
17
18    #[error("corrupt payload: {0}")]
19    CorruptPayload(String),
20
21    #[error("compression failed: {0}")]
22    CompressionFailed(String),
23
24    #[error("decompression failed: {0}")]
25    DecompressionFailed(String),
26
27    #[error("digest mismatch: expected {expected}, got {got}")]
28    DigestMismatch { expected: String, got: String },
29
30    #[error("dimensionality mismatch: expected {expected}, got {got}")]
31    DimensionMismatch { expected: usize, got: usize },
32
33    #[error("layer index out of bounds: {index} of {total}")]
34    LayerIndexOutOfBounds { index: u32, total: u32 },
35
36    #[error("empty corpus: cannot build pool from zero tokens")]
37    EmptyCorpus,
38
39    #[error("codec unavailable: codec '{codec}' requires feature '{feature}'")]
40    CodecUnavailable { codec: String, feature: String },
41
42    #[error("internal error: {0}")]
43    Internal(String),
44
45    #[error("serialization error: {0}")]
46    Serialization(#[from] serde_json::Error),
47
48    #[error("I/O error: {0}")]
49    Io(#[from] std::io::Error),
50}
51
52/// Result type alias for poly-kv.
53pub type Result<T> = std::result::Result<T, PolyKvError>;