agcodex_persistence/
error.rs

1//! Error types for persistence operations
2
3use std::io;
4use thiserror::Error;
5use uuid::Uuid;
6
7pub type Result<T> = std::result::Result<T, PersistenceError>;
8
9#[derive(Error, Debug)]
10pub enum PersistenceError {
11    /// I/O errors during file operations
12    #[error("I/O error: {0}")]
13    Io(#[from] io::Error),
14
15    /// Bincode encoding errors
16    #[error("Bincode encoding error: {0}")]
17    BincodeEncode(#[from] bincode::error::EncodeError),
18
19    /// Bincode decoding errors
20    #[error("Bincode decoding error: {0}")]
21    BincodeDecode(#[from] bincode::error::DecodeError),
22
23    /// MessagePack serialization errors
24    #[error("MessagePack serialization error: {0}")]
25    MessagePack(#[from] rmp_serde::encode::Error),
26
27    /// MessagePack deserialization errors
28    #[error("MessagePack deserialization error: {0}")]
29    MessagePackDecode(#[from] rmp_serde::decode::Error),
30
31    /// Compression errors
32    #[error("Compression error: {0}")]
33    Compression(String),
34
35    /// Session not found
36    #[error("Session not found: {0}")]
37    SessionNotFound(Uuid),
38
39    /// Invalid magic bytes in file header
40    #[error("Invalid file format: expected AGCX magic bytes")]
41    InvalidMagic,
42
43    /// Unsupported format version
44    #[error("Unsupported format version: {0} (expected {1})")]
45    UnsupportedVersion(u16, u16),
46
47    /// Corrupt session data
48    #[error("Corrupt session data: {0}")]
49    CorruptData(String),
50
51    /// Invalid format
52    #[error("Invalid format: {0}")]
53    InvalidFormat(String),
54
55    /// Incompatible version
56    #[error("Incompatible version: expected {expected}, got {actual}")]
57    IncompatibleVersion { expected: u16, actual: u16 },
58
59    /// Storage path does not exist
60    #[error("Storage path does not exist: {0}")]
61    PathNotFound(String),
62
63    /// Permission denied
64    #[error("Permission denied: {0}")]
65    PermissionDenied(String),
66
67    /// Session already exists
68    #[error("Session already exists: {0}")]
69    SessionAlreadyExists(Uuid),
70
71    /// Invalid checkpoint
72    #[error("Invalid checkpoint: {0}")]
73    InvalidCheckpoint(String),
74
75    /// Migration required
76    #[error("Migration required from version {0} to {1}")]
77    MigrationRequired(u16, u16),
78
79    /// Migration failed
80    #[error("Migration failed: {0}")]
81    MigrationFailed(String),
82
83    /// Lock acquisition failed
84    #[error("Failed to acquire lock: {0}")]
85    LockFailed(String),
86
87    /// Memory map error
88    #[error("Memory mapping failed: {0}")]
89    MemoryMapFailed(String),
90
91    /// Index corruption
92    #[error("Session index corrupted: {0}")]
93    IndexCorrupted(String),
94
95    /// Auto-save failed
96    #[error("Auto-save failed: {0}")]
97    AutoSaveFailed(String),
98
99    /// JSON serialization error
100    #[error("JSON error: {0}")]
101    Json(#[from] serde_json::Error),
102}