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
//! Error types for index persistence operations.
use std::path::PathBuf;
use thiserror::Error;
/// Errors that can occur during index persistence operations.
#[derive(Debug, Error)]
pub enum IndexPersistenceError {
/// Index file is corrupted or invalid
#[error("Index file corrupted: {path}")]
Corrupted {
/// Path to the corrupted file
path: PathBuf,
#[source]
/// Source error
source: Box<dyn std::error::Error + Send + Sync>,
},
/// String interner index mismatch during restoration
#[error("String interner mismatch: expected index {expected}, got {got}")]
InternerMismatch {
/// Expected index value
expected: u32,
/// Actual index value received
got: u32,
},
/// Manifest version not supported
#[error("Manifest version {found} not supported (max supported: {supported})")]
UnsupportedVersion {
/// Version found in manifest
found: u16,
/// Maximum supported version
supported: u16,
},
/// Required index file is missing
#[error("Missing required index file: {name}")]
MissingIndex {
/// Name of missing index file
name: String,
},
/// Invalid magic bytes in file header
#[error("Invalid magic bytes in {path}: expected {expected:?}, got {got:?}")]
InvalidMagic {
/// Path to file with invalid magic bytes
path: PathBuf,
/// Expected magic bytes
expected: [u8; 4],
/// Actual magic bytes found
got: [u8; 4],
},
/// Size limit exceeded (DoS protection)
#[error("Size limit exceeded: {message}")]
SizeLimitExceeded {
/// Description of the size limit violation
message: String,
},
/// IO error during persistence operations
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
/// Bitcode serialization/deserialization error
#[error("Serialization error: {0}")]
Serialization(String),
}
impl From<bitcode::Error> for IndexPersistenceError {
fn from(e: bitcode::Error) -> Self {
IndexPersistenceError::Serialization(e.to_string())
}
}
impl IndexPersistenceError {
/// Check if this error is due to a file not being found.
pub fn is_not_found(&self) -> bool {
matches!(
self,
IndexPersistenceError::Io(e) if e.kind() == std::io::ErrorKind::NotFound
)
}
}
/// Result type for index persistence operations.
pub type Result<T> = std::result::Result<T, IndexPersistenceError>;