git_project/
err.rs

1use auto_from::From;
2use std::{fmt, io};
3
4pub type Result<T> = std::result::Result<T, Err>;
5
6#[derive(Debug, From)]
7pub enum Err {
8    InvalidUrl,
9    NonDomainHost,
10    NoHost,
11    Io(io::Error),
12    Git2(git2::Error),
13    Walkdir(walkdir::Error),
14    SubcommandFailed(Option<i32>),
15}
16
17impl fmt::Display for Err {
18    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
19        let s = match self {
20            Err::InvalidUrl => "Invalid URL".into(),
21            Err::NoHost => "URL is required to have a host".into(),
22            Err::NonDomainHost => "URL host is required to be a domain name".into(),
23            Err::Io(e) => format!("I/O Error: {}", e),
24            Err::Git2(e) => format!("Git library Error: {}", e),
25            Err::Walkdir(e) => format!("Error walking directory tree: {}", e),
26            Err::SubcommandFailed(Some(code)) => {
27                format!("Subcommand failed with exit code {}", code)
28            }
29            Err::SubcommandFailed(None) => "Subcommand failed".into(),
30        };
31
32        write!(f, "{}", s)
33    }
34}