forked from memvid/memvid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.rs
More file actions
233 lines (177 loc) · 6.52 KB
/
error.rs
File metadata and controls
233 lines (177 loc) · 6.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
use std::borrow::Cow;
use std::path::PathBuf;
use thiserror::Error;
/// Result alias used throughout the core crate.
pub type Result<T> = std::result::Result<T, MemvidError>;
/// Process metadata for a lock holder used to produce human readable diagnostics.
#[derive(Debug, Clone)]
pub struct LockOwnerHint {
pub pid: Option<u32>,
pub cmd: Option<String>,
pub started_at: Option<String>,
pub file_path: Option<PathBuf>,
pub file_id: Option<String>,
pub last_heartbeat: Option<String>,
pub heartbeat_ms: Option<u64>,
}
/// Structured error returned when a `.mv2` is locked by another writer.
#[derive(Debug, Error, Clone)]
#[error("{message}")]
pub struct LockedError {
pub file: PathBuf,
pub message: String,
pub owner: Option<LockOwnerHint>,
pub stale: bool,
}
impl LockedError {
#[must_use]
pub fn new(
file: PathBuf,
message: impl Into<String>,
owner: Option<LockOwnerHint>,
stale: bool,
) -> Self {
Self {
file,
message: message.into(),
owner,
stale,
}
}
}
/// Canonical error surface for memvid-core.
#[derive(Debug, Error)]
pub enum MemvidError {
#[error("I/O error: {source}")]
Io {
source: std::io::Error,
path: Option<PathBuf>,
},
#[error("Serialization error: {0}")]
Encode(#[from] bincode::error::EncodeError),
#[error("Deserialization error: {0}")]
Decode(#[from] bincode::error::DecodeError),
#[error("Lock acquisition failed: {0}")]
Lock(String),
#[error(transparent)]
Locked(#[from] LockedError),
#[error("Checksum mismatch while validating {context}")]
ChecksumMismatch { context: &'static str },
#[error("Header validation failed: {reason}")]
InvalidHeader { reason: Cow<'static, str> },
#[error("This file is encrypted: {path}\n{hint}")]
EncryptedFile { path: PathBuf, hint: String },
#[error("Table of contents validation failed: {reason}")]
InvalidToc { reason: Cow<'static, str> },
#[error("Time index track is invalid: {reason}")]
InvalidTimeIndex { reason: Cow<'static, str> },
#[error("Sketch track is invalid: {reason}")]
InvalidSketchTrack { reason: Cow<'static, str> },
#[cfg(feature = "temporal_track")]
#[error("Temporal track is invalid: {reason}")]
InvalidTemporalTrack { reason: Cow<'static, str> },
#[error("Logic-Mesh is invalid: {reason}")]
InvalidLogicMesh { reason: Cow<'static, str> },
#[error("Logic-Mesh is not enabled")]
LogicMeshNotEnabled,
#[error("NER model not available: {reason}")]
NerModelNotAvailable { reason: Cow<'static, str> },
#[error("Unsupported tier requested")]
InvalidTier,
#[error("Lexical index is not enabled")]
LexNotEnabled,
#[error("Vector index is not enabled")]
VecNotEnabled,
#[error("CLIP index is not enabled")]
ClipNotEnabled,
#[error("Vector dimension mismatch (expected {expected}, got {actual})")]
VecDimensionMismatch { expected: u32, actual: usize },
#[error("Auxiliary file detected: {path:?}")]
AuxiliaryFileDetected { path: PathBuf },
#[error("Embedded WAL is corrupted at offset {offset}: {reason}")]
WalCorruption {
offset: u64,
reason: Cow<'static, str>,
},
#[error("Manifest WAL is corrupted at offset {offset}: {reason}")]
ManifestWalCorrupted { offset: u64, reason: &'static str },
#[error("Unable to checkpoint embedded WAL: {reason}")]
CheckpointFailed { reason: String },
#[error("Ticket sequence is out of order (expected > {expected}, got {actual})")]
TicketSequence { expected: i64, actual: i64 },
#[error("Apply a ticket before mutating this memory (tier {tier:?})")]
TicketRequired { tier: crate::types::Tier },
#[error(
"Capacity exceeded. Current: {current} bytes, Limit: {limit} bytes, Required: {required} bytes"
)]
CapacityExceeded {
current: u64,
limit: u64,
required: u64,
},
#[error("API key required for files larger than {limit} bytes. File size: {file_size} bytes")]
ApiKeyRequired { file_size: u64, limit: u64 },
#[error(
"Memory already bound to '{existing_memory_name}' ({existing_memory_id}). Bound at: {bound_at}"
)]
MemoryAlreadyBound {
existing_memory_id: uuid::Uuid,
existing_memory_name: String,
bound_at: String,
},
#[error("Operation requires a sealed memory")]
RequiresSealed,
#[error("Operation requires an open memory")]
RequiresOpen,
#[error("Doctor command requires at least one operation")]
DoctorNoOp,
#[error("Doctor operation failed: {reason}")]
Doctor { reason: String },
#[error("Feature '{feature}' is not available in this build")]
FeatureUnavailable { feature: &'static str },
#[error("Invalid search cursor: {reason}")]
InvalidCursor { reason: &'static str },
#[error("Invalid frame {frame_id}: {reason}")]
InvalidFrame {
frame_id: crate::types::FrameId,
reason: &'static str,
},
#[error("Frame {frame_id} was not found")]
FrameNotFound { frame_id: crate::types::FrameId },
#[error("Frame with uri '{uri}' was not found")]
FrameNotFoundByUri { uri: String },
#[error("Ticket signature verification failed: {reason}")]
TicketSignatureInvalid { reason: Box<str> },
#[error("Model signature verification failed: {reason}")]
ModelSignatureInvalid { reason: Box<str> },
#[error("Model manifest invalid: {reason}")]
ModelManifestInvalid { reason: Box<str> },
#[error("Model integrity check failed: {reason}")]
ModelIntegrity { reason: Box<str> },
#[error("Extraction failed: {reason}")]
ExtractionFailed { reason: Box<str> },
#[error("Embedding failed: {reason}")]
EmbeddingFailed { reason: Box<str> },
#[error("Reranking failed: {reason}")]
RerankFailed { reason: Box<str> },
#[error("Invalid query: {reason}")]
InvalidQuery { reason: String },
#[error("Tantivy error: {reason}")]
Tantivy { reason: String },
#[error("Table extraction failed: {reason}")]
TableExtraction { reason: String },
#[error("Schema validation failed: {reason}")]
SchemaValidation { reason: String },
}
impl From<std::io::Error> for MemvidError {
fn from(source: std::io::Error) -> Self {
Self::Io { source, path: None }
}
}
impl From<tantivy::TantivyError> for MemvidError {
fn from(value: tantivy::TantivyError) -> Self {
Self::Tantivy {
reason: value.to_string(),
}
}
}