use std::path::PathBuf;
use std::time::Duration;
#[derive(Debug, thiserror::Error)]
pub enum CleanupError {
#[error("Failed to remove worktree at {path}: {source}")]
RemovalFailed {
path: PathBuf,
source: std::io::Error,
},
#[error("Worktree cleanup timeout after {timeout:?}")]
Timeout { timeout: Duration },
#[error("Worktree is still active and cannot be cleaned")]
WorktreeActive,
#[error("Git operation failed: {0}")]
GitError(String),
#[error("Permission denied for worktree cleanup: {path}")]
PermissionDenied { path: PathBuf },
#[error("Resource limit exceeded: {0}")]
ResourceLimitExceeded(String),
#[error("Cleanup coordinator error: {0}")]
CoordinatorError(String),
}
impl CleanupError {
pub fn is_recoverable(&self) -> bool {
matches!(
self,
CleanupError::Timeout { .. } | CleanupError::WorktreeActive
)
}
pub fn should_retry(&self) -> bool {
matches!(self, CleanupError::Timeout { .. })
}
}
pub type CleanupResult<T> = Result<T, CleanupError>;