summaryrefslogtreecommitdiffstats
path: root/asyncgit/src/error.rs
blob: 80c490fe316d128fa8278ed01967fe7f69bf5a5b (plain)
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
#![allow(renamed_and_removed_lints, clippy::unknown_clippy_lints)]

use std::{num::TryFromIntError, string::FromUtf8Error};
use thiserror::Error;

#[derive(Error, Debug)]
pub enum Error {
    #[error("`{0}`")]
    Generic(String),

    #[error("git: no head found")]
    NoHead,

    #[error("git: remote url not found")]
    UnknownRemote,

    #[error("git: inconclusive remotes")]
    NoDefaultRemoteFound,

    #[error("git: work dir error")]
    NoWorkDir,

    #[error("git: uncommitted changes")]
    UncommittedChanges,

    #[error("git: can\u{2019}t run blame on a binary file")]
    NoBlameOnBinaryFile,

    #[error("binary file")]
    BinaryFile,

    #[error("io error:{0}")]
    Io(#[from] std::io::Error),

    #[error("git error:{0}")]
    Git(#[from] git2::Error),

    #[error("utf8 error:{0}")]
    Utf8Conversion(#[from] FromUtf8Error),

    #[error("TryFromInt error:{0}")]
    IntConversion(#[from] TryFromIntError),

    #[error("EasyCast error:{0}")]
    EasyCast(#[from] easy_cast::Error),
}

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

impl<T> From<std::sync::PoisonError<T>> for Error {
    fn from(error: std::sync::PoisonError<T>) -> Self {
        Self::Generic(format!("poison error: {}", error))
    }
}

impl<T> From<crossbeam_channel::SendError<T>> for Error {
    fn from(error: crossbeam_channel::SendError<T>) -> Self {
        Self::Generic(format!("send error: {}", error))
    }
}