use thiserror::Error;
use crate::source::{KernelError, SourceError};
use crate::sync::state::StateError;
#[derive(Debug, Error)]
pub enum Error {
#[error(transparent)]
SourceCtx(#[from] SourceError),
#[error("config error: transitive source `{name}` at depth {depth}: {source}")]
TransitiveSource {
name: String,
depth: usize,
#[source]
source: SourceError,
},
#[error(transparent)]
StateCtx(#[from] StateError),
#[error("io error: {0}")]
Io(#[from] std::io::Error),
#[error("config error: {0}")]
Config(String),
#[error("lock error: {0}")]
Lock(String),
#[error("matcher error: {0}")]
Matcher(#[from] globset::Error),
#[error("source error: {0}")]
Source(String),
#[error("root path not found in tree: {root}")]
RootNotFound { root: std::path::PathBuf },
#[error("symlink not allowed: {path} (set allow_symlinks=true to permit)")]
SymlinkNotAllowed { path: std::path::PathBuf },
#[error("registry error: {0}")]
StateStore(String),
#[error("projection error: {0}")]
Projection(String),
#[error("sync error: {0}")]
Sync(String),
#[error("artifact `{artifact}` collides in target `{target}` from sources: {sources:?}")]
Collision {
artifact: String,
sources: Vec<String>,
target: String,
},
#[error("not implemented: {0}")]
NotImplemented(&'static str),
#[error("aborted by user")]
Aborted,
}
impl From<KernelError> for Error {
fn from(err: KernelError) -> Self {
Self::SourceCtx(SourceError::from(err))
}
}
pub type Result<T> = std::result::Result<T, Error>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn not_implemented_renders() {
assert!(
Error::NotImplemented("x")
.to_string()
.contains("not implemented")
);
}
}