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
#[derive(Debug, thiserror::Error)]
pub enum ErrorKind {
    /// Parser failed.
    #[error("parser failed")]
    Parser,
    /// Cannot convert from Utf-8.
    #[error("cannot convert from Utf-8 {0}")]
    FromUtf8(std::str::Utf8Error),
    /// IO error.
    #[error("IO error {0}")]
    IO(#[from] std::io::Error),
    /// Invalid path.
    #[error("Invalid path {0}")]
    InvalidPath(String),
    /// RevisionLog load failure.
    #[error("revision log load failure {0}")]
    RevisionLogFailure(String),
    /// Cannot convert date/time.
    #[error("invalid date time {0}")]
    InvalidDateTime(String),
    /// Requirement in ``.hg/requires`` is not supported.
    #[error("unknown requirement {0}")]
    UnknownRequirement(String),
    /// Manifest issue.
    #[error("manifest issue {0}")]
    Manifest(String),
}

impl From<nom::Err<nom::error::Error<&[u8]>>> for ErrorKind {
    fn from(_value: nom::Err<nom::error::Error<&[u8]>>) -> Self {
        ErrorKind::Parser
    }
}

impl From<chrono::format::ParseError> for ErrorKind {
    fn from(value: chrono::format::ParseError) -> Self {
        ErrorKind::InvalidDateTime(format!("{:?}", value))
    }
}

impl From<std::str::Utf8Error> for ErrorKind {
    fn from(value: std::str::Utf8Error) -> Self {
        ErrorKind::FromUtf8(value)
    }
}