use thiserror::Error;
#[derive(Debug, Error)]
pub enum FrostxError {
#[error("no frostx.toml found in {0}")]
NotInitialized(std::path::PathBuf),
#[error("UUID collision: current path {current} differs from state-recorded path {recorded}. Run `frostx init --force` to assign a new UUID.")]
UuidCollision {
current: std::path::PathBuf,
recorded: std::path::PathBuf,
},
#[error("frostx.toml already exists; pass --force to overwrite")]
AlreadyInitialized,
#[error("{0}")]
Config(String),
#[error("include error in {path}: {message}")]
Include { path: String, message: String },
#[error("{0}")]
UnknownAction(String),
#[error("action '{action}' failed: {message}")]
ActionFailed { action: String, message: String },
#[error("backup config missing: add [config.backup] server = \"...\" to frostx.toml")]
BackupConfigMissing,
#[error("io error: {0}")]
Io(#[from] std::io::Error),
#[error("{0}")]
Other(#[from] anyhow::Error),
}
pub mod exit_code {
pub const OK: i32 = 0;
pub const ERROR: i32 = 1;
pub const WARNING: i32 = 2;
pub const NOT_INITIALIZED: i32 = 3;
pub const UUID_COLLISION: i32 = 4;
}
impl FrostxError {
#[must_use]
pub fn exit_code(&self) -> i32 {
match self {
Self::NotInitialized(_) => exit_code::NOT_INITIALIZED,
Self::UuidCollision { .. } => exit_code::UUID_COLLISION,
_ => exit_code::ERROR,
}
}
}