1use log::{debug, error, info, trace, warn};
3
4use std::ffi::OsString;
5use std::fmt::Debug;
6use std::io;
7use thiserror::Error as ThisError;
8
9#[allow(missing_docs)]
12#[derive(ThisError, Debug)]
13pub enum Error {
14 #[error("Sorry. {0} is not implemented yet")]
15 Todo(&'static str),
16 #[error("Regex Error: {source}")]
17 RegexError {
18 #[from]
19 source: regex::Error,
20 },
21 #[error("TOML Serialization Error: {source}")]
22 TomlSerializationError {
23 #[from]
24 source: toml::ser::Error,
25 },
26
27 #[error("TOML Deserialization Error: {source}")]
28 TomlDeserializationError {
29 #[from]
30 source: toml::de::Error,
31 },
32
33 #[error("Yaml Error: {source}")]
34 YamlError {
35 #[from]
36 source: serde_yaml::Error,
37 },
38 #[error("Encountered NULL value in YAML map")]
39 YamlNullValueForKey { key: String },
40 #[error("I/O Error: {source}")]
41 IoError {
42 #[from]
43 source: io::Error,
44 },
45 #[error("Cannot convert enum type from string: {cause_key}")]
46 EnumTypeConversionError { cause_key: String },
47 #[error("Config source for level {config_source:?} not found at {path:?}")]
48 ConfigurationForSourceNotFound {
49 config_source: String,
50 path: OsString,
51 },
52
53 #[error("Config value type mismatch: {key} ")]
54 MismatchedValueType { key: String },
55 #[error("Config key not found: {key}")]
56 ConfigKeyNotFound { key: String },
57 #[error("Cannot Determine System Configuration Path")]
58 CannotDetermineSystemConfigurationPath,
59
60 #[error("Cannot Determine User Configuration Path")]
61 CannotDetermineUserConfigurationPath,
62 #[error("Enum Parsing Error")]
63 StrumError {
64 #[from]
65 source: strum::ParseError,
66 },
67}
68
69impl Error {
70 pub fn debug(self) -> Self {
72 debug!("{}", self);
73 self
74 }
75 pub fn trace(self) -> Self {
77 trace!("{}", self);
78 self
79 }
80 pub fn warn(self) -> Self {
82 warn!("{}", self);
83 self
84 }
85 pub fn error(self) -> Self {
87 error!("{}", self);
88 self
89 }
90 pub fn info(self) -> Self {
92 info!("{}", self);
93 self
94 }
95 pub fn panic(self) -> Self {
97 panic!("{}", self);
98 }
99}
100
101pub type Result<T> = std::result::Result<T, Error>;