use thiserror::Error;
use super::ApplyError;
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum DiffError {
#[error(transparent)]
Apply(#[from] ApplyError),
#[error(transparent)]
Arguments(#[from] crate::diff::ResolveDiffArgumentsError),
#[error(transparent)]
FuncnamePattern(#[from] crate::userdiff::FuncnamePatternError),
#[error(transparent)]
Pickaxe(#[from] crate::diff::pickaxe::PickaxeError),
#[error(transparent)]
NoIndex(crate::diff::NoIndexError),
#[error(transparent)]
HunkSelection(#[from] crate::porcelain::hunk_select::HunkSelectError),
#[error("cannot blame the working tree of a bare repository")]
BlameWorktreeBareRepository,
#[error("cannot find revision {rev} to ignore")]
BlameIgnoreRevUnknown {
rev: String,
},
#[error("could not open object name list: {path}")]
BlameIgnoreRevsFileOpen {
path: String,
#[source]
source: std::io::Error,
},
#[error("invalid object name: {rev}")]
BlameIgnoreRevsFileInvalidRev {
path: String,
rev: String,
},
#[error("blame copy detection supports at most three levels, got {count}")]
BlameCopyLevelTooHigh {
count: usize,
},
#[error("could not run textconv command '{command}': {source}")]
TextconvSpawn {
command: String,
#[source]
source: std::io::Error,
},
#[error("textconv command '{command}' exited with status {}", status.map_or_else(|| "unknown".to_owned(), |s| s.to_string()))]
TextconvFailed {
command: String,
status: Option<i32>,
},
}
impl DiffError {
#[must_use]
pub fn kind_name(&self) -> &'static str {
match self {
Self::Apply(..) => "apply",
Self::Arguments(..) => "diff_arguments",
Self::NoIndex(..) => "no_index",
Self::FuncnamePattern(..) => "funcname_pattern",
Self::Pickaxe(..) => "pickaxe",
Self::HunkSelection(..) => "hunk_selection",
Self::BlameWorktreeBareRepository => "blame_worktree_bare_repository",
Self::BlameIgnoreRevUnknown { .. } => "blame_ignore_rev_unknown",
Self::BlameIgnoreRevsFileOpen { .. } => "blame_ignore_revs_file_open",
Self::BlameIgnoreRevsFileInvalidRev { .. } => "blame_ignore_revs_file_invalid_rev",
Self::BlameCopyLevelTooHigh { .. } => "blame_copy_level_too_high",
Self::TextconvSpawn { .. } => "textconv_spawn",
Self::TextconvFailed { .. } => "textconv_failed",
}
}
}