#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
pub enum RepoPathError {
#[error("repository path is empty")]
Empty,
#[error("repository path contains a NUL byte")]
Nul,
#[error("repository path must be relative")]
Absolute,
#[error("repository path contains '.' or '..' component")]
Traversal,
}
impl From<std::convert::Infallible> for RepoPathError {
fn from(value: std::convert::Infallible) -> Self {
match value {}
}
}
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[error("unknown diff scope `{0}`; expected unstaged, staged, or both")]
pub struct ParseDiffScopeError(pub String);
#[derive(Debug, thiserror::Error)]
pub enum DiffError {
#[error("unsupported path encoding: {0}")]
UnsupportedPathEncoding(#[source] std::str::Utf8Error),
#[error("invalid repository path: {0}")]
InvalidPath(#[from] RepoPathError),
#[error("failed to parse diff: {source}")]
Parse {
#[source]
source: diffy::patch_set::PatchSetParseError,
},
#[error("invalid UTF-8: {0}")]
Utf8(#[from] std::str::Utf8Error),
#[error("invalid git porcelain v1 record")]
InvalidPorcelainEntry,
}
impl From<std::string::FromUtf8Error> for DiffError {
fn from(error: std::string::FromUtf8Error) -> Self {
Self::UnsupportedPathEncoding(error.utf8_error())
}
}