use std::path::PathBuf;
use thiserror::Error;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum SafetyLockError {
#[error(
"DOTFILES_ROOT is set but empty — unset it to let dodot discover the \
root, or point it at your dotfiles directory"
)]
EnvironmentRootEmpty,
#[error("DOTFILES_ROOT is set to `{spelling}` but {reason}")]
EnvironmentRootUnusable {
spelling: String,
reason: String,
},
#[error("the {selected_by} `{spelling}` cannot be used as a dotfiles root: {reason}")]
ImplicitRootUnusable {
spelling: String,
selected_by: super::roots::RootSource,
reason: String,
},
#[error("`{spelling}` is not an absolute path, so it cannot identify a dotfiles root")]
RelativeRootIdentity { spelling: String },
#[error(
"`{spelling}` contains `..`, so it names an alias rather than a \
dotfiles root — pass the resolved path instead"
)]
NonCanonicalRootIdentity { spelling: String },
#[error("`{spelling}` is not a valid dotfiles-root spelling: {reason}")]
UnreadableSpelling { spelling: String, reason: String },
#[error(
"cannot anchor the relative path `{spelling}`: the current directory no \
longer exists — pass an absolute path, or the exact spelling `dodot \
roots list` prints"
)]
RelativeArgumentUnanchorable { spelling: String },
#[error("cannot read the trusted-roots file at {}: {reason}", path.display())]
TrustStateUnusable { path: PathBuf, reason: String },
#[error("cannot write the trusted-roots file at {}: {reason}", path.display())]
TrustStateNotWritable { path: PathBuf, reason: String },
#[error("the trusted-roots file lists `{spelling}` more than once")]
DuplicateApprovedRoot { spelling: String },
#[error(
"`{spelling}` was selected by DOTFILES_ROOT, which is already deliberate \
selection — environment roots are never added to the approved roots"
)]
EnvironmentRootNotApprovable { spelling: String },
#[error("cannot load the dotfiles configuration at {}: {reason}", config_file.display())]
DotfilesConfigUnusable {
config_file: PathBuf,
reason: String,
},
#[error("cannot inspect the packs under {}: {reason}", directory.display())]
PackRoutingUnusable {
directory: PathBuf,
reason: String,
},
}
pub type Result<T> = std::result::Result<T, SafetyLockError>;