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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//
pub type Result<T> = core::result::Result<T, Error>;

#[derive(Debug, thiserror::Error)]
pub enum Error {
    #[error("lock")]
    Lock,

    #[error("File not found: {}", 0)]
    NotFound(String),

    #[error("Unable to parse file contents")]
    ParseContent,

    #[error("Unable to decode from base64")]
    DecodeFromBase64,

    #[error("Unable to decode from UTF-8")]
    DecodeFromUtf8,

    #[error("Unknown file encoding: {}", 0)]
    UnknownEncoding(String),

    #[error("Not a file: {}", 0)]
    NotFile(String),

    #[error("Unknown error (status: {})", 0)]
    Unknown(String),

    #[error("commit log: {0}")]
    CommitLog(#[from] crate::commit::log::Error),

    #[error("commit not found")]
    CommitNotFound,

    #[error("no tree in commit")]
    NoTreeInCommit(String),

    #[error("no .git-next.toml file found in repo")]
    FileNotFound,

    #[error("find reference: {0}")]
    FindReference(String),

    #[error("find object: {0}")]
    FindObject(String),

    #[error("Non-UTF-8 in blob: {0}")]
    NonUtf8Blob(String),

    #[error("try id")]
    TryId,
}

mod gix_errors {
    #![cfg(not(tarpaulin_include))] // third-party library errors
    use super::Error;
    impl From<gix::reference::find::existing::Error> for Error {
        fn from(value: gix::reference::find::existing::Error) -> Self {
            Self::FindReference(value.to_string())
        }
    }

    impl From<gix::object::commit::Error> for Error {
        fn from(value: gix::object::commit::Error) -> Self {
            Self::NoTreeInCommit(value.to_string())
        }
    }

    impl From<gix::object::find::existing::Error> for Error {
        fn from(value: gix::object::find::existing::Error) -> Self {
            Self::FindObject(value.to_string())
        }
    }

    impl From<std::string::FromUtf8Error> for Error {
        fn from(value: std::string::FromUtf8Error) -> Self {
            Self::NonUtf8Blob(value.to_string())
        }
    }
}