dot_agent_core/
error.rs

1use std::path::PathBuf;
2use thiserror::Error;
3
4#[derive(Debug, Error)]
5pub enum DotAgentError {
6    #[error("Profile not found: {name}")]
7    ProfileNotFound { name: String },
8
9    #[error("Target directory does not exist: {path}")]
10    TargetNotFound { path: PathBuf },
11
12    #[error("Profile already exists: {name}")]
13    ProfileAlreadyExists { name: String },
14
15    #[error("Invalid profile name: '{name}' - must contain only alphanumeric, hyphen, underscore")]
16    InvalidProfileName { name: String },
17
18    #[error("Conflict detected - file exists with different content: {path}")]
19    Conflict { path: PathBuf },
20
21    #[error("Local modifications detected: {paths:?}")]
22    LocalModifications { paths: Vec<PathBuf> },
23
24    #[error("IO error: {0}")]
25    Io(#[from] std::io::Error),
26
27    #[error("TOML serialization error: {0}")]
28    TomlSer(#[from] toml::ser::Error),
29
30    #[error("TOML deserialization error: {0}")]
31    TomlDe(#[from] toml::de::Error),
32
33    #[error("Home directory not found")]
34    HomeNotFound,
35
36    #[error("GUI error: {0}")]
37    Gui(String),
38
39    #[error("Git error: {0}")]
40    Git(String),
41}
42
43pub type Result<T> = std::result::Result<T, DotAgentError>;
44
45impl DotAgentError {
46    pub fn exit_code(&self) -> i32 {
47        match self {
48            Self::ProfileNotFound { .. } => 2,
49            Self::TargetNotFound { .. } => 3,
50            Self::LocalModifications { .. } => 4,
51            Self::InvalidProfileName { .. } => 5,
52            Self::Conflict { .. } => 6,
53            _ => 1,
54        }
55    }
56}