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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
use log::{debug, error, info, trace, warn};
use std::ffi::OsString;
use std::fmt::Debug;
use std::io;
use thiserror::Error as ThisError;
#[allow(missing_docs)]
#[derive(ThisError, Debug)]
pub enum Error {
#[error("Sorry. {0} is not implemented yet")]
Todo(&'static str),
#[error("Regex Error: {source}")]
RegexError {
#[from]
source: regex::Error,
},
#[error("TOML Serialization Error: {source}")]
TomlSerializationError {
#[from]
source: toml::ser::Error,
},
#[error("TOML Deserialization Error: {source}")]
TomlDeserializationError {
#[from]
source: toml::de::Error,
},
#[error("Yaml Error: {source}")]
YamlError {
#[from]
source: serde_yaml::Error,
},
#[error("Encountered NULL value in YAML map")]
YamlNullValueForKey { key: String },
#[error("I/O Error: {source}")]
IoError {
#[from]
source: io::Error,
},
#[error("Cannot convert enum type from string: {cause_key}")]
EnumTypeConversionError { cause_key: String },
#[error("Config source for level {config_source:?} not found at {path:?}")]
ConfigurationForSourceNotFound {
config_source: String,
path: OsString,
},
#[error("Config value type mismatch: {key} ")]
MismatchedValueType { key: String },
#[error("Config key not found: {key}")]
ConfigKeyNotFound { key: String },
#[error("Cannot Determine System Configuration Path")]
CannotDetermineSystemConfigurationPath,
#[error("Cannot Determine User Configuration Path")]
CannotDetermineUserConfigurationPath,
#[error("Enum Parsing Error")]
StrumError {
#[from]
source: strum::ParseError,
},
}
impl Error {
pub fn debug(self) -> Self {
debug!("{}", self);
self
}
pub fn trace(self) -> Self {
trace!("{}", self);
self
}
pub fn warn(self) -> Self {
warn!("{}", self);
self
}
pub fn error(self) -> Self {
error!("{}", self);
self
}
pub fn info(self) -> Self {
info!("{}", self);
self
}
pub fn panic(self) -> Self {
panic!("{}", self);
}
}
pub type Result<T> = std::result::Result<T, Error>;