use std::fmt;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum VcsError {
#[error("object not found: {id}")]
ObjectNotFound {
id: crate::ObjectId,
},
#[error("ref not found: {name}")]
RefNotFound {
name: String,
},
#[error("HEAD is detached")]
DetachedHead,
#[error("nothing staged")]
NothingStaged,
#[error("validation failed: {reasons:?}")]
ValidationFailed {
reasons: Vec<String>,
},
#[error("merge conflict: {count} conflict(s)")]
MergeConflicts {
count: usize,
},
#[error("branch already exists: {name}")]
BranchExists {
name: String,
},
#[error("not a panproto repository")]
NotARepository,
#[error("expected {expected} object, found {found}")]
WrongObjectType {
expected: &'static str,
found: &'static str,
},
#[error("io error: {0}")]
Io(#[from] std::io::Error),
#[error("serialization error: {0}")]
Serialization(SerializationError),
#[error("compose error: {0}")]
Compose(#[from] panproto_mig::ComposeError),
#[error("no common ancestor found")]
NoCommonAncestor,
#[error("no path found between commits")]
NoPath,
}
#[derive(Debug)]
pub struct SerializationError(pub String);
impl fmt::Display for SerializationError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.0)
}
}
impl From<rmp_serde::encode::Error> for VcsError {
fn from(e: rmp_serde::encode::Error) -> Self {
Self::Serialization(SerializationError(e.to_string()))
}
}
impl From<rmp_serde::decode::Error> for VcsError {
fn from(e: rmp_serde::decode::Error) -> Self {
Self::Serialization(SerializationError(e.to_string()))
}
}