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
use failure::Fail;

use prettyprint::PrettyPrintError;
use std::io::Error as IoError;
use std::string::FromUtf8Error;

#[derive(Debug, Fail)]
/// Custom type for inspection errors
pub enum InspectError {
    /// Error during I/O handling
    #[fail(display = "{}", _0)]
    Io(#[fail(cause)] IoError),
    /// Error when invoking rustc
    #[fail(display = "{}", _0)]
    Rustc(String),
    /// Error when converting data to UTF8
    #[fail(display = "{}", _0)]
    Utf8(#[fail(cause)] FromUtf8Error),
    /// Error while invoking rustfmt
    #[fail(display = "{}", _0)]
    Rustfmt(String),
    /// Error while invoking prettyprint
    #[fail(display = "{}", _0)]
    PrettyPrint(String),
    /// Error while trying to generate a flowgraph
    #[fail(display = "{}", _0)]
    Flowgraph(String),
    /// Error invoking `dot`
    #[fail(display = "{}", _0)]
    DotExec(#[fail(cause)] IoError),
    /// Other error
    #[fail(display = "{}", _0)]
    Generic(String),
}

impl From<IoError> for InspectError {
    fn from(e: IoError) -> Self {
        InspectError::Io(e)
    }
}

impl From<FromUtf8Error> for InspectError {
    fn from(e: FromUtf8Error) -> Self {
        InspectError::Utf8(e)
    }
}

impl From<String> for InspectError {
    fn from(e: String) -> Self {
        InspectError::Generic(e)
    }
}

impl From<PrettyPrintError> for InspectError {
    fn from(e: PrettyPrintError) -> Self {
        InspectError::PrettyPrint(e.description().to_string())
    }
}