use std::path::PathBuf;
#[derive(Debug, thiserror::Error)]
pub enum DotlingError {
#[error("dotling repo not found — run `dotling init <path>` first")]
RepoNotFound,
#[error("already initialized at {0}")]
AlreadyInitialized(PathBuf),
#[error("path not found: {0}")]
PathNotFound(PathBuf),
#[error("path is outside home directory: {0}")]
PathOutsideHome(PathBuf),
#[error("already tracked: {0}")]
AlreadyTracked(PathBuf),
#[error("not tracked: {0}")]
NotTracked(PathBuf),
#[error("destination conflict — unmanaged file exists at {0}")]
DestinationConflict(PathBuf),
#[error("git: {0}")]
Git(String),
#[error("{path}: {source}")]
Io {
path: PathBuf,
source: std::io::Error,
},
#[error("failed to parse config: {0}")]
ConfigParse(String),
#[error("failed to write config: {0}")]
#[allow(dead_code)]
ConfigWrite(String),
#[error("no git remote configured — add one with `git remote add origin <url>`")]
NoRemote,
#[error("already a symlink: {0}")]
AlreadySymlink(PathBuf),
}
pub fn io_err(path: &std::path::Path) -> impl FnOnce(std::io::Error) -> DotlingError + '_ {
move |source| DotlingError::Io {
path: path.to_path_buf(),
source,
}
}
pub type Result<T> = std::result::Result<T, DotlingError>;