ricecoder_undo_redo/
error.rs

1//! Error types for the undo/redo system
2
3use thiserror::Error;
4
5/// Errors that can occur in the undo/redo system
6#[derive(Debug, Error)]
7pub enum UndoRedoError {
8    /// Change not found in history
9    #[error("Change not found: {0}")]
10    ChangeNotFound(String),
11
12    /// Checkpoint not found
13    #[error("Checkpoint not found: {0}")]
14    CheckpointNotFound(String),
15
16    /// No more undos available
17    #[error("No more undos available")]
18    NoMoreUndos,
19
20    /// No more redos available
21    #[error("No more redos available")]
22    NoMoreRedos,
23
24    /// Storage error
25    #[error("Storage error: {0}")]
26    StorageError(String),
27
28    /// Validation error
29    #[error("Validation error: {0}")]
30    ValidationError(String),
31
32    /// Serialization error
33    #[error("Serialization error: {0}")]
34    SerializationError(#[from] serde_json::Error),
35
36    /// IO error
37    #[error("IO error: {0}")]
38    IoError(#[from] std::io::Error),
39}
40
41impl UndoRedoError {
42    /// Create a new ChangeNotFound error with context
43    pub fn change_not_found(id: impl Into<String>) -> Self {
44        Self::ChangeNotFound(id.into())
45    }
46
47    /// Create a new CheckpointNotFound error with context
48    pub fn checkpoint_not_found(id: impl Into<String>) -> Self {
49        Self::CheckpointNotFound(id.into())
50    }
51
52    /// Create a new StorageError with context
53    pub fn storage_error(msg: impl Into<String>) -> Self {
54        Self::StorageError(msg.into())
55    }
56
57    /// Create a new ValidationError with context
58    pub fn validation_error(msg: impl Into<String>) -> Self {
59        Self::ValidationError(msg.into())
60    }
61}