Skip to main content

opencode_ralph_loop_cli/
error.rs

1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum CliError {
5    #[error("generic error: {0}")]
6    Generic(String),
7    #[error("invalid argument: {0}")]
8    Usage(String),
9    #[error("conflict without --force: {path}")]
10    Conflict { path: String },
11    #[error("I/O error at {path}: {source}")]
12    Io {
13        path: String,
14        #[source]
15        source: std::io::Error,
16    },
17    #[error("drift detected in strict mode")]
18    DriftStrict,
19    #[error("manifest missing or corrupted")]
20    ManifestMissing,
21    #[error("failed to parse configuration: {0}")]
22    ConfigParse(String),
23    #[error("interrupted by SIGINT")]
24    Sigint,
25}
26
27impl CliError {
28    pub fn exit_code(&self) -> i32 {
29        match self {
30            CliError::Generic(_) => 1,
31            CliError::Usage(_) => 2,
32            CliError::Conflict { .. } => 3,
33            CliError::Io { .. } => 4,
34            CliError::DriftStrict => 5,
35            CliError::ManifestMissing => 6,
36            CliError::ConfigParse(_) => 7,
37            CliError::Sigint => 130,
38        }
39    }
40
41    pub fn io(path: impl Into<String>, source: std::io::Error) -> Self {
42        CliError::Io {
43            path: path.into(),
44            source,
45        }
46    }
47}