summary refs log tree commit diff stats
path: root/pkgs/by-name/ba/back/src/error/mod.rs
blob: 7e1c9cf624dc30fe5814d6951acf0e1fe26c1999 (plain) (blame)
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
use std::{fmt::Display, io, path::PathBuf};

use thiserror::Error;

pub type Result<T> = std::result::Result<T, Error>;

#[derive(Error, Debug)]
pub enum Error {
    ConfigParse {
        file: PathBuf,
        error: serde_json::Error,
    },
    ConfigRead {
        file: PathBuf,
        error: io::Error,
    },
    RepoOpen {
        repository_path: PathBuf,
        error: Box<gix::open::Error>,
    },
    RocketLaunch(#[from] rocket::Error),
}

impl Display for Error {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Error::ConfigParse { file, error } => {
                write!(
                    f,
                    "while trying to parse the config file ({}): {error}",
                    file.display()
                )
            }
            Error::ConfigRead { file, error } => {
                write!(
                    f,
                    "while trying to read the config file ({}): {error}",
                    file.display()
                )
            }
            Error::RepoOpen {
                repository_path,
                error,
            } => {
                write!(
                    f,
                    "while trying to open the repository ({}): {error}",
                    repository_path.display()
                )
            }
            Error::RocketLaunch(error) => {
                write!(f, "while trying to start back: {error}")
            }
        }
    }
}