pub type Result<T, E = Error> = std::result::Result<T, E>;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error("invalid reference name {name:?}: {reason}")]
InvalidRefName {
name: String,
reason: &'static str,
},
#[error("refname conflict: {name} cannot exist while {conflicts_with} does")]
RefNameConflict {
name: String,
conflicts_with: String,
},
#[error("object {oid} is corrupt: {reason}")]
CorruptObject {
oid: gix_hash::ObjectId,
reason: String,
},
#[error("object {id} is referenced{} but is not in the store", match referrer {
Some(from) => format!(" by {from}"),
None => String::new(),
})]
MissingObject {
id: gix_hash::ObjectId,
referrer: Option<gix_hash::ObjectId>,
},
#[error("hash kind mismatch: store holds {stored}, was opened as {requested}")]
HashKindMismatch {
stored: gix_hash::Kind,
requested: gix_hash::Kind,
},
#[error(
"the store is locked by another writer ({}); its owner is still running, or could \
not be shown to be gone. Clear the lock only if no gunnar is running against it",
path.display()
)]
StoreLocked {
path: std::path::PathBuf,
},
#[error("could not compute an object hash")]
Hash(#[source] gix_error::Error),
#[error(transparent)]
Io(#[from] std::io::Error),
#[error(transparent)]
Backend(#[from] anyhow::Error),
}
impl Error {
pub fn is_name_conflict(&self) -> bool {
matches!(self, Error::RefNameConflict { .. })
}
pub fn backend(msg: impl std::fmt::Display) -> Self {
Error::Backend(anyhow::anyhow!("{msg}"))
}
}
impl From<gix_error::Exn<gix_error::Message>> for Error {
fn from(err: gix_error::Exn<gix_error::Message>) -> Self {
Error::Hash(err.into())
}
}