Skip to main content

ralph_workflow/checkpoint/file_state/
error.rs

1/// Validation errors for file system state.
2#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
3pub enum ValidationError {
4    /// A file that should exist is missing
5    FileMissing { path: String },
6
7    /// A file that shouldn't exist unexpectedly exists
8    FileUnexpectedlyExists { path: String },
9
10    /// A file's content has changed
11    FileContentChanged { path: String },
12
13    /// Git HEAD has changed
14    GitHeadChanged { expected: String, actual: String },
15
16    /// Git working tree has changes (files modified, staged, etc.)
17    GitWorkingTreeChanged { changes: String },
18
19    /// Git state is invalid
20    GitStateInvalid { reason: String },
21}
22
23impl std::fmt::Display for ValidationError {
24    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25        match self {
26            Self::FileMissing { path } => write!(f, "File missing: {}", path),
27            Self::FileUnexpectedlyExists { path } => write!(f, "File unexpectedly exists: {}", path),
28            Self::FileContentChanged { path } => write!(f, "File content changed: {}", path),
29            Self::GitHeadChanged { expected, actual } => {
30                write!(f, "Git HEAD changed: expected {}, got {}", expected, actual)
31            }
32            Self::GitWorkingTreeChanged { changes } => {
33                write!(f, "Git working tree changed: {}", changes)
34            }
35            Self::GitStateInvalid { reason } => write!(f, "Git state invalid: {}", reason),
36        }
37    }
38}
39
40impl std::error::Error for ValidationError {}