1use thiserror::Error;
4
5use super::ApplyError;
6
7#[derive(Debug, Error)]
11#[non_exhaustive]
12pub enum DiffError {
13 #[error(transparent)]
15 Apply(#[from] ApplyError),
16
17 #[error(transparent)]
19 Arguments(#[from] crate::diff::ResolveDiffArgumentsError),
20
21 #[error(transparent)]
23 FuncnamePattern(#[from] crate::userdiff::FuncnamePatternError),
24
25 #[error(transparent)]
27 Pickaxe(#[from] crate::diff::pickaxe::PickaxeError),
28
29 #[error(transparent)]
31 NoIndex(crate::diff::NoIndexError),
32
33 #[error(transparent)]
35 HunkSelection(#[from] crate::porcelain::hunk_select::HunkSelectError),
36
37 #[error("cannot blame the working tree of a bare repository")]
39 BlameWorktreeBareRepository,
40
41 #[error("cannot find revision {rev} to ignore")]
43 BlameIgnoreRevUnknown {
44 rev: String,
46 },
47
48 #[error("could not open object name list: {path}")]
50 BlameIgnoreRevsFileOpen {
51 path: String,
53 #[source]
55 source: std::io::Error,
56 },
57
58 #[error("invalid object name: {rev}")]
60 BlameIgnoreRevsFileInvalidRev {
61 path: String,
63 rev: String,
65 },
66
67 #[error("blame copy detection supports at most three levels, got {count}")]
69 BlameCopyLevelTooHigh {
70 count: usize,
72 },
73
74 #[error("could not run textconv command '{command}': {source}")]
76 TextconvSpawn {
77 command: String,
79 #[source]
81 source: std::io::Error,
82 },
83
84 #[error("textconv command '{command}' exited with status {}", status.map_or_else(|| "unknown".to_owned(), |s| s.to_string()))]
86 TextconvFailed {
87 command: String,
89 status: Option<i32>,
91 },
92}
93
94impl DiffError {
95 #[must_use]
97 pub fn kind_name(&self) -> &'static str {
98 match self {
99 Self::Apply(..) => "apply",
100 Self::Arguments(..) => "diff_arguments",
101 Self::NoIndex(..) => "no_index",
102 Self::FuncnamePattern(..) => "funcname_pattern",
103 Self::Pickaxe(..) => "pickaxe",
104 Self::HunkSelection(..) => "hunk_selection",
105 Self::BlameWorktreeBareRepository => "blame_worktree_bare_repository",
106 Self::BlameIgnoreRevUnknown { .. } => "blame_ignore_rev_unknown",
107 Self::BlameIgnoreRevsFileOpen { .. } => "blame_ignore_revs_file_open",
108 Self::BlameIgnoreRevsFileInvalidRev { .. } => "blame_ignore_revs_file_invalid_rev",
109 Self::BlameCopyLevelTooHigh { .. } => "blame_copy_level_too_high",
110 Self::TextconvSpawn { .. } => "textconv_spawn",
111 Self::TextconvFailed { .. } => "textconv_failed",
112 }
113 }
114}