tuneutils/
error.rs

1use std::result;
2use std::io;
3use std::fmt;
4
5
6#[derive(Debug)]
7pub enum Error {
8	Io(io::Error),
9	Eval(eval::Error),
10	InvalidConnection,
11    InvalidResponse,
12    Timeout,
13    TooMuchData,
14    IncompleteWrite,
15    Read,
16    // ISO-TP Frame
17    InvalidFrame,
18
19    NegativeResponse(u8),
20    InvalidPacket,
21
22    Yaml(serde_yaml::Error),
23    InvalidPlatformId,
24    InvalidModelId,
25    InvalidRomId,
26    NotLoaded,
27    InvalidTableId,
28    NoTableOffset,
29
30    /// Received an empty packet
31    EmptyPacket,
32    
33    #[cfg(feature = "j2534")]
34    J2534(j2534::Error),
35}
36
37pub type Result<T> = result::Result<T, Error>;
38
39impl From<io::Error> for Error {
40    fn from(error: io::Error) -> Self {
41        Error::Io(error)
42    }
43}
44
45impl From<serde_yaml::Error> for Error {
46    fn from(err: serde_yaml::Error) -> Error {
47        Error::Yaml(err)
48    }
49}
50
51impl From<eval::Error> for Error {
52    fn from(err: eval::Error) -> Error {
53        Error::Eval(err)
54    }
55}
56
57impl fmt::Display for Error {
58    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
59        match *self {
60            Error::Io(ref err) => write!(f, "IO error: {}", err),
61            Error::Eval(ref err) => write!(f, "Eval error: {}", err),
62            Error::InvalidConnection => write!(f, "Invalid connection"),
63            Error::InvalidResponse => write!(f, "Invalid response"),
64            Error::Timeout => write!(f, "Timed out"),
65            Error::TooMuchData => write!(f, "Too much data"),
66            Error::IncompleteWrite => write!(f, "Failed to finish writing data"),
67            Error::Read => write!(f, "Read failed"),
68            Error::InvalidFrame => write!(f, "Invalid frame"),
69            Error::NegativeResponse(code) => write!(f, "Negative ISO-TP response received ({})", code),
70            Error::InvalidPacket => write!(f, "Invalid packet received"),
71            Error::Yaml(ref err) => write!(f, "Yaml error: {}", err),
72            Error::InvalidPlatformId => write!(f, "Invalid platform id"),
73            Error::InvalidModelId => write!(f, "Invalid model id"),
74            Error::InvalidRomId => write!(f, "Invalid rom id"),
75            Error::NotLoaded => write!(f, "Not loaded"),
76            Error::InvalidTableId => write!(f, "Invalid table id"),
77            Error::NoTableOffset => write!(f, "No table offset"),
78            Error::EmptyPacket => write!(f, "Received an empty packet"),
79            #[cfg(feature = "j2534")]
80            Error::J2534(ref err) => write!(f, "J2534 error: {}", err),
81            _ => write!(f, "unimplemented: {:?}", *self),
82        }
83    }
84}