-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy patherror.rs
50 lines (45 loc) · 1.29 KB
/
error.rs
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
use std::error::Error as StdError;
use std::fmt::{Display, Error as FmtError, Formatter};
use std::io::Error as IoError;
#[derive(Debug)]
pub enum Error {
GitInstallation,
CurrentBranchInvalid,
InvalidRemote,
ExitEarly,
Io(IoError),
}
use self::Error::*;
impl StdError for Error {
fn source(&self) -> Option<&(dyn StdError + 'static)> {
match *self {
Io(ref io_error) => Some(io_error),
_ => None,
}
}
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter) -> Result<(), FmtError> {
match *self {
Io(ref io_error) => io_error.fmt(f),
ExitEarly => Ok(()),
GitInstallation => {
write!(f, "Unable to execute 'git' on your machine, please make sure it's installed and on your PATH")
}
CurrentBranchInvalid => {
write!(
f,
"Please make sure to run git-clean from your base branch (defaults to main)."
)
}
InvalidRemote => {
write!(f, "That remote doesn't exist, please make sure to use a valid remote (defaults to origin).")
}
}
}
}
impl From<IoError> for Error {
fn from(error: IoError) -> Error {
Io(error)
}
}