summaryrefslogtreecommitdiff
path: root/src/error.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/error.rs b/src/error.rs
index dbe7224..612a2e2 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -15,9 +15,11 @@ pub enum ErrorType {
15 ArgumentCountError, 15 ArgumentCountError,
16 ConfigError, 16 ConfigError,
17 DBError, 17 DBError,
18 ModError,
18 LibToml, 19 LibToml,
19 LibSql, 20 LibSql,
20 LibReq, 21 LibReq,
22 LibChrono,
21 IoError, 23 IoError,
22 Other, 24 Other,
23} 25}
@@ -31,13 +33,15 @@ impl std::error::Error for MLError {
31impl fmt::Display for MLError { 33impl fmt::Display for MLError {
32 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 34 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
33 match self.etype { 35 match self.etype {
34 ErrorType::ArgumentError => write!(f, "Wrong argument"), 36 ErrorType::ArgumentError => write!(f, "User input not accepted: {}", self.message),
35 ErrorType::ArgumentCountError => write!(f, "Too many/too few arguments"), 37 ErrorType::ArgumentCountError => write!(f, "Too many/too few arguments"),
36 ErrorType::ConfigError => write!(f, "CONFIG"), 38 ErrorType::ConfigError => write!(f, "CONFIG"),
37 ErrorType::DBError => write!(f, "DATABASE"), 39 ErrorType::DBError => write!(f, "Database: {}", self.message),
40 ErrorType::ModError => write!(f, "Mod: {}", self.message),
38 ErrorType::LibToml => write!(f, "TOML"), 41 ErrorType::LibToml => write!(f, "TOML"),
39 ErrorType::LibSql => write!(f, "SQL"), 42 ErrorType::LibSql => write!(f, "SQL"),
40 ErrorType::LibReq => write!(f, "REQWEST"), 43 ErrorType::LibReq => write!(f, "REQWEST"),
44 ErrorType::LibChrono => write!(f, "Chrono error: {}", self.message),
41 ErrorType::IoError => write!(f, "IO"), 45 ErrorType::IoError => write!(f, "IO"),
42 ErrorType::Other => write!(f, "OTHER") 46 ErrorType::Other => write!(f, "OTHER")
43 } 47 }
@@ -68,6 +72,12 @@ impl From<toml::ser::Error> for MLError {
68 } 72 }
69} 73}
70 74
75impl From<chrono::ParseError> for MLError {
76 fn from(error: chrono::ParseError) -> Self {
77 Self { etype: ErrorType::LibChrono, message: error.to_string() }
78 }
79}
80
71impl From<std::io::Error> for MLError { 81impl From<std::io::Error> for MLError {
72 fn from(error: std::io::Error) -> Self { 82 fn from(error: std::io::Error) -> Self {
73 Self { etype: ErrorType::IoError, message: error.to_string() } 83 Self { etype: ErrorType::IoError, message: error.to_string() }