git_clone_canonical/
error.rs1use std::path::PathBuf;
2
3pub type Result<T> = std::result::Result<T, Error>;
4
5#[derive(Debug, derive_more::From)]
6pub enum Error {
7 Cli(clap::Error),
8 InvalidRepoPath(PathBuf),
9 IO(std::io::Error),
10 ChildExit(String, Option<i32>),
11 LogInit(log::SetLoggerError),
12}
13
14impl Error {
15 pub fn exit(self) -> ! {
16 use Error::*;
17
18 match self {
19 Cli(e) => e.exit(),
20 InvalidRepoPath(p) => log::error!("invalid repository path; {:?}", p.display()),
21 IO(e) => log::error!("{}", e),
22 ChildExit(cmd, code) => {
23 log::error!("child exited with error code {:?}", code);
24 log::error!("child command: {}", cmd);
25 }
26 LogInit(e) => log::error!("failed to initialize logging; {}", e),
27 }
28
29 std::process::exit(1);
30 }
31}