1use thiserror::Error;
2
3#[derive(Debug, Error)]
4pub enum UrnaError {
5 #[error("I/O error: {0}")]
6 Io(#[from] std::io::Error),
7 #[error("magic mismatch: expected {expected:?}, got {got:?}")]
8 MagicMismatch { expected: [u8; 4], got: [u8; 4] },
9 #[error("unsupported version: {0}.{1}")]
10 UnsupportedVersion(u16, u16),
11 #[error("unsupported format_version: {0}")]
12 UnsupportedFormatVersion(u32),
13 #[error("unsupported schema_version: {0}")]
14 UnsupportedSchemaVersion(u32),
15 #[error("invalid header checksum")]
16 InvalidHeaderChecksum,
17 #[error("section {section_id} offset out of bounds: {offset}")]
18 SectionOffsetOutOfBounds { section_id: u32, offset: u64 },
19 #[error("section {0} checksum mismatch")]
20 SectionChecksumMismatch(u32),
21 #[error("section {0} not found")]
22 SectionNotFound(u32),
23 #[error("unsupported section payload version: section={section_id} version={version}")]
24 UnsupportedSectionVersion { section_id: u32, version: u32 },
25 #[error("unsupported section encoding: section={section_id} encoding={encoding}")]
26 UnsupportedSectionEncoding { section_id: u32, encoding: u32 },
27 #[error("section {section_id} offset not aligned: offset={offset} alignment={alignment}")]
28 SectionMisaligned {
29 section_id: u32,
30 offset: u64,
31 alignment: u64,
32 },
33 #[error("malformed section payload: section={section_id} reason={reason}")]
34 MalformedSectionPayload { section_id: u32, reason: String },
35 #[error("footer hash mismatch")]
36 FooterHashMismatch,
37 #[error("file size mismatch: expected {expected}, got {got}")]
38 FileSizeMismatch { expected: u64, got: u64 },
39 #[error("file truncated")]
40 FileTruncated,
41 #[error("manifest invalid: {0}")]
42 ManifestInvalid(String),
43 #[error("missing required section: {0}")]
44 MissingRequiredSection(&'static str),
45 #[error("embedding size mismatch: expected {expected}, got {got}")]
46 EmbeddingSizeMismatch { expected: usize, got: usize },
47 #[error("section count mismatch: section={section_id} expected={expected} got={got}")]
48 SectionCountMismatch {
49 section_id: u32,
50 expected: usize,
51 got: usize,
52 },
53 #[error("unsupported dtype: {0}")]
54 UnsupportedDType(String),
55 #[error("unsupported metric: {0}")]
56 UnsupportedMetric(String),
57 #[error("unsupported score_type: {0}")]
58 UnsupportedScoreType(String),
59 #[error("unsupported normalize: {0}")]
60 UnsupportedNormalize(String),
61 #[error("unsupported index_type: {0}")]
62 UnsupportedIndexType(String),
63 #[error("unsupported rerank_policy: {0}")]
64 UnsupportedRerankPolicy(String),
65 #[error("invalid model_hash: {0}")]
66 InvalidModelHash(String),
67 #[error("NaN or Inf detected in embeddings")]
68 InvalidEmbeddingValue,
69 #[error("JSON error: {0}")]
70 Json(#[from] serde_json::Error),
71 #[error("query validation failed: {0}")]
72 QueryValidation(String),
73 #[error("dimension mismatch: expected {expected}, got {got}")]
74 DimensionMismatch { expected: usize, got: usize },
75 #[error("invalid k parameter: {0}")]
76 InvalidK(i32),
77 #[error("empty query")]
78 EmptyQuery,
79 #[error("zero-norm query")]
80 ZeroNormQuery,
81 #[error("file not found: {0}")]
82 FileNotFound(String),
83 #[error("unexpected end of file")]
84 UnexpectedEof,
85 #[error("unsupported feature: {0}")]
86 UnsupportedFeature(String),
87 #[error("invalid input: {0}")]
88 InvalidInput(String),
89}
90
91pub type Result<T> = std::result::Result<T, UrnaError>;