Skip to main content

ralph_workflow/checkpoint/file_state/
error.rs

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