-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy patherror.rs
More file actions
183 lines (177 loc) · 8.35 KB
/
error.rs
File metadata and controls
183 lines (177 loc) · 8.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
use std::{fmt::Display, io, string};
#[derive(Debug)]
pub enum Error {
StashList(git2::Error),
ReadLog(git2::Error),
OpenRepo(git2::Error),
FindGitDir(io::Error),
Term(io::Error),
GitDirUtf8(string::FromUtf8Error),
Config(Box<figment::Error>),
Bindings { bad_key_bindings: Vec<String> },
FileWatcher(notify::Error),
ReadRebaseStatusFile(io::Error),
ReadBranchName(io::Error),
BranchNameUtf8(Utf8Error),
GitDiff(io::Error),
GitDiffUtf8(string::FromUtf8Error),
GitShow(io::Error),
GitShowUtf8(string::FromUtf8Error),
GitShowMeta(git2::Error),
NotOnBranch,
GetHead(git2::Error),
CurrentBranchName(git2::Error),
GetCurrentBranchUpstream(git2::Error),
GetCurrentBranchUpstreamUtf8(Utf8Error),
RemoteNameUtf8(Utf8Error),
CannotDeleteCurrentBranch,
BranchNameRequired,
IsBranchMerged(git2::Error),
GetRemote(git2::Error),
ReadGitConfig(git2::Error),
ReadGitConfigUtf8(Utf8Error),
DeleteGitConfig(git2::Error),
SetGitConfig(git2::Error),
RemoteHasNoName,
ReadOid(git2::Error),
ArgMustBePositiveNumber,
ArgInvalidRegex(regex::Error),
Clipboard(crate::clipboard::ClipboardError),
FindGitRev(git2::Error),
NoEditorSet,
GitStatus(git2::Error),
CmdAlreadyRunning,
StashWorkTreeEmpty,
CouldntAwaitCmd(io::Error),
NoRepoWorkdir,
SpawnCmd(io::Error),
CmdBadExit(String, Option<i32>),
CouldntReadCmdOutput(io::Error),
ListGitReferences(git2::Error),
OpenLogFile(io::Error),
PromptAborted,
NoMoreEvents,
CannotSpinoffCurrentBranch,
SpinoffBranchExists(String),
DoesBranchExist(git2::Error),
GetBranchName(git2::Error),
BaseCommitOid,
UpstreamCommitOid,
}
impl std::error::Error for Error {}
impl Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::StashList(e) => f.write_fmt(format_args!("Couldn't list stash: {e}")),
Error::ReadLog(e) => f.write_fmt(format_args!("Couldn't read log: {e}")),
Error::OpenRepo(e) => match e.code() {
git2::ErrorCode::NotFound => f.write_str("No .git found in the current directory"),
_ => f.write_fmt(format_args!("Couldn't open repo: {e:?}")),
},
Error::FindGitDir(e) => f.write_fmt(format_args!("Couldn't find git directory: {}", e)),
Error::Term(e) => f.write_fmt(format_args!("Terminal error: {}", e)),
Error::GitDirUtf8(_e) => f.write_str("Git directory not valid UTF-8"),
Error::Config(e) => f.write_fmt(format_args!("Configuration error: {e}")),
Error::Bindings { bad_key_bindings } => {
let mut error_string = String::from("Errors while parsing key bindings:");
for item in bad_key_bindings {
error_string.push_str(&format!("\n{item}"));
}
f.write_fmt(format_args!("{error_string}"))
}
Error::FileWatcher(e) => f.write_fmt(format_args!("File watcher error: {e}")),
Error::ReadRebaseStatusFile(e) => {
f.write_fmt(format_args!("Couldn't read rebase status file: {e}"))
}
Error::ReadBranchName(e) => f.write_fmt(format_args!("Couldn't read branch name: {e}")),
Error::BranchNameUtf8(_e) => f.write_str("Branch name error"),
Error::GitDiff(e) => f.write_fmt(format_args!("Git diff error: {e}")),
Error::GitDiffUtf8(e) => {
f.write_fmt(format_args!("Git diff output is not valid UTF-8: {e}"))
}
Error::GitShow(e) => f.write_fmt(format_args!("Git show error: {e}")),
Error::GitShowUtf8(e) => {
f.write_fmt(format_args!("Git show output is not valid UTF-8: {e}"))
}
Error::GitShowMeta(e) => f.write_fmt(format_args!("Git show metadata error: {e}")),
Error::NotOnBranch => f.write_str("Head is not a branch"),
Error::GetHead(e) => f.write_fmt(format_args!("Couldn't get HEAD: {e}")),
Error::CurrentBranchName(e) => {
f.write_fmt(format_args!("Couldn't get current branch name: {e}"))
}
Error::GetCurrentBranchUpstream(e) => {
f.write_fmt(format_args!("Couldn't get current branch upstream: {e}"))
}
Error::GetCurrentBranchUpstreamUtf8(_e) => {
f.write_str("Current branch upstream is not valid UTF-8")
}
Error::RemoteNameUtf8(_e) => f.write_str("Remote name is not valid UTF-8"),
Error::CannotDeleteCurrentBranch => f.write_str("Cannot delete current branch"),
Error::BranchNameRequired => f.write_str("Branch name required"),
Error::IsBranchMerged(e) => {
f.write_fmt(format_args!("Couldn't check if branch is merged: {e}"))
}
Error::GetRemote(e) => f.write_fmt(format_args!("Couldn't get remote: {e}")),
Error::ReadGitConfig(e) => f.write_fmt(format_args!("Couldn't read git config: {e}")),
Error::ReadGitConfigUtf8(_e) => f.write_str("Git config is not valid UTF-8"),
Error::DeleteGitConfig(e) => {
f.write_fmt(format_args!("Couldn't delete git config: {e}"))
}
Error::SetGitConfig(e) => f.write_fmt(format_args!("Couldn't set git config: {e}")),
Error::RemoteHasNoName => f.write_str("Remote has no name"),
Error::ReadOid(e) => f.write_fmt(format_args!("Couldn't read OID: {e}")),
Error::ArgMustBePositiveNumber => f.write_str("Value must be a number greater than 0"),
Error::ArgInvalidRegex(e) => f.write_fmt(format_args!("Invalid regex: {e}")),
Error::Clipboard(e) => f.write_fmt(format_args!("Clipboard error: {e}")),
Error::FindGitRev(e) => f.write_fmt(format_args!("Couldn't find git revision: {e}")),
Error::NoEditorSet => f.write_fmt(format_args!(
"No editor environment variable set ({})",
crate::ops::show::EDITOR_VARS.join(", ")
)),
Error::GitStatus(e) => f.write_fmt(format_args!("Git status error: {e}")),
Error::CmdAlreadyRunning => f.write_str("A command is already running"),
Error::StashWorkTreeEmpty => f.write_str("Cannot stash: working tree is empty"),
Error::CouldntAwaitCmd(e) => f.write_fmt(format_args!("Couldn't await command: {e}")),
Error::NoRepoWorkdir => f.write_str("No repository working directory"),
Error::SpawnCmd(e) => f.write_fmt(format_args!("Failed to spawn command: {e}")),
Error::CmdBadExit(args, code) => f.write_fmt(format_args!(
"'{}' exited with code: {}",
args,
code.map(|c| c.to_string())
.unwrap_or_else(|| "".to_string())
)),
Error::CouldntReadCmdOutput(e) => {
f.write_fmt(format_args!("Couldn't read command output: {e}"))
}
Error::ListGitReferences(e) => {
f.write_fmt(format_args!("Couldn't list git references: {e}"))
}
Error::OpenLogFile(e) => f.write_fmt(format_args!("Couldn't open log file: {e}")),
Error::PromptAborted => f.write_str("Aborted"),
Error::NoMoreEvents => unimplemented!(),
Error::CannotSpinoffCurrentBranch => f.write_str("Cannot spin-off current branch"),
Error::SpinoffBranchExists(new_branch_name) => f.write_fmt(format_args!(
"Cannot spin-off {new_branch_name}. It already exists"
)),
Error::DoesBranchExist(e) => {
f.write_fmt(format_args!("Couldn't check if branch exists: {}", e))
}
Error::GetBranchName(e) => f.write_fmt(format_args!("Couldn't get branch name: {}", e)),
Error::BaseCommitOid => f.write_str("Could not resolve OID of base commit"),
Error::UpstreamCommitOid => {
f.write_str("Could not resolve OID of upstream branch commit")
}
}
}
}
#[derive(Debug)]
pub enum Utf8Error {
Str(std::str::Utf8Error),
String(string::FromUtf8Error),
}
impl std::error::Error for Utf8Error {}
impl Display for Utf8Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("not valid UTF-8")
}
}