ruvector_snapshot/
error.rs

1use thiserror::Error;
2
3/// Result type for snapshot operations
4pub type Result<T> = std::result::Result<T, SnapshotError>;
5
6/// Errors that can occur during snapshot operations
7#[derive(Error, Debug)]
8pub enum SnapshotError {
9    #[error("Snapshot not found: {0}")]
10    SnapshotNotFound(String),
11
12    #[error("Corrupted snapshot: {0}")]
13    CorruptedSnapshot(String),
14
15    #[error("Storage error: {0}")]
16    StorageError(String),
17
18    #[error("Compression error: {0}")]
19    CompressionError(String),
20
21    #[error("IO error: {0}")]
22    IoError(#[from] std::io::Error),
23
24    #[error("Serialization error: {0}")]
25    SerializationError(String),
26
27    #[error("JSON error: {0}")]
28    JsonError(#[from] serde_json::Error),
29
30    #[error("Invalid checksum: expected {expected}, got {actual}")]
31    InvalidChecksum { expected: String, actual: String },
32
33    #[error("Collection error: {0}")]
34    CollectionError(String),
35}
36
37impl SnapshotError {
38    /// Create a storage error with a custom message
39    pub fn storage<S: Into<String>>(msg: S) -> Self {
40        SnapshotError::StorageError(msg.into())
41    }
42
43    /// Create a corrupted snapshot error with a custom message
44    pub fn corrupted<S: Into<String>>(msg: S) -> Self {
45        SnapshotError::CorruptedSnapshot(msg.into())
46    }
47
48    /// Create a compression error with a custom message
49    pub fn compression<S: Into<String>>(msg: S) -> Self {
50        SnapshotError::CompressionError(msg.into())
51    }
52}