Skip to main content

tequel/error/
mod.rs

1
2/// Enum that represents some Types of Error in Tequel.
3#[derive(Debug)]
4pub enum TequelError {
5    /// When Hash is invalid
6    InvalidHash,
7
8    /// When occurr some error with the decode from HEX to UTF-8
9    InvalidHex(String),
10
11    /// When MACs not match
12    InvalidMac,
13
14    /// When occurr error while trying decode HEX to UTF-8
15    InvalidUtf8,
16
17    /// When key is don't provided or is different
18    KeyError(String),
19
20}
21
22impl std::fmt::Display for TequelError {
23    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24        match self {
25            TequelError::InvalidHash => write!(f, "Hash is Invalid"),
26            TequelError::InvalidHex(s) => write!(f, "Hex is Invalid: {}", s),
27            TequelError::InvalidMac => write!(f, "MACs not match. Data has changed! Key? Data?"),
28            TequelError::InvalidUtf8 => write!(f, "Error UTF-8 convertion. Incorrect Key?"),
29            TequelError::KeyError(e) => write!(f, "Key Error: {}", e)
30        }
31    }
32}
33
34
35impl std::error::Error for TequelError {}