use std::path::PathBuf;
#[derive(Debug, thiserror::Error)]
pub enum ProjectError {
#[error("invalid project id {0:?}: expected a 26-character ULID")]
InvalidId(String),
#[error("{path}: {source}")]
Io {
path: PathBuf,
#[source]
source: std::io::Error,
},
#[error("{path}: {message}")]
Parse { path: PathBuf, message: String },
#[error("serialize {path}: {message}")]
Serialize { path: PathBuf, message: String },
#[error("{path}: unsupported schema version {found} (this build supports up to {supported})")]
UnsupportedSchema {
path: PathBuf,
found: u32,
supported: u32,
},
#[error("{path}: file name does not match manifest id {id}")]
IdMismatch { path: PathBuf, id: String },
#[error("{0}: project root is not an existing directory")]
BadRoot(PathBuf),
#[error("nested project refused: {0}")]
NestedRefused(String),
#[error(
"{root} is the registered home of project {id}; fork the copy instead \
(or pass force to archive this manifest and mint a new identity here)"
)]
RegisteredHome { id: String, root: PathBuf },
#[error(
"project {id} at {root} is already registered for {existing}; \
if {root} is a copy, run `weft project init --fork` there to give it its own identity"
)]
RootConflict {
id: String,
root: PathBuf,
existing: PathBuf,
},
}
impl ProjectError {
pub(crate) fn io(path: impl Into<PathBuf>, source: std::io::Error) -> Self {
Self::Io {
path: path.into(),
source,
}
}
}