use std::path::PathBuf;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("no target directory at {0}")]
SourceMissing(PathBuf),
#[error("{0} already exists")]
DestinationExists(PathBuf),
#[error("a previous run left a partial tree at {0}; remove it and run again")]
StagingExists(PathBuf),
#[error("a build is running here: {path} is locked; seed between builds")]
SourceBusy { path: PathBuf },
#[error("{0} has no parent directory to be created in")]
DestinationHasNoParent(PathBuf),
#[error("{dest} is inside {src}, which is the directory being read")]
DestinationInsideSource { src: PathBuf, dest: PathBuf },
#[error(
"{src} and {dest} are on different filesystems, so there is nothing to share between them"
)]
CrossDevice { src: PathBuf, dest: PathBuf },
#[error("{op} {path}")]
Io {
op: &'static str,
path: PathBuf,
#[source]
source: std::io::Error,
},
#[error("walking {path}")]
Walk {
path: PathBuf,
#[source]
source: walkdir::Error,
},
#[error("running `cargo metadata`")]
MetadataSpawn(#[source] std::io::Error),
#[error("`cargo metadata` failed: {0}")]
MetadataFailed(String),
#[error("reading the output of `cargo metadata`")]
MetadataParse(#[source] serde_json::Error),
#[error("`cargo metadata` reported no target directory")]
MetadataNoTargetDir,
}
pub type Result<T> = std::result::Result<T, Error>;
impl Error {
pub(crate) fn io(
op: &'static str,
path: impl Into<PathBuf>,
) -> impl FnOnce(std::io::Error) -> Error {
let path = path.into();
move |source| Error::Io { op, path, source }
}
}