summaryrefslogtreecommitdiff
path: root/src/error.rs
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2024-09-04 11:12:04 +0200
committerfxqnlr <[email protected]>2024-09-04 11:12:04 +0200
commit6a91d0a864f9edd9d9fe50ca89ccbce4fc98e043 (patch)
treeae04cf34582f57699d12ac7b5b486ab065bf8d19 /src/error.rs
parentf5e070cdf6628a5ebd981d373929802317104e24 (diff)
downloadmodlist-6a91d0a864f9edd9d9fe50ca89ccbce4fc98e043.tar
modlist-6a91d0a864f9edd9d9fe50ca89ccbce4fc98e043.tar.gz
modlist-6a91d0a864f9edd9d9fe50ca89ccbce4fc98e043.zip
do nearly anything to shut clippy up
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs70
1 files changed, 36 insertions, 34 deletions
diff --git a/src/error.rs b/src/error.rs
index b4cc444..652fa0c 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -1,16 +1,16 @@
1use core::fmt; 1use core::fmt;
2use serde::Deserialize; 2use serde::Deserialize;
3 3
4pub type MLE<T> = Result<T, MLError>; 4pub type MLE<T> = Result<T, MLErr>;
5 5
6#[derive(Debug, Deserialize)] 6#[derive(Debug, Deserialize)]
7pub struct MLError { 7pub struct MLErr {
8 etype: ErrorType, 8 etype: EType,
9 message: String, 9 message: String,
10} 10}
11 11
12#[derive(Debug, Deserialize)] 12#[derive(Debug, Deserialize)]
13pub enum ErrorType { 13pub enum EType {
14 ArgumentError, 14 ArgumentError,
15 ArgumentCountError, 15 ArgumentCountError,
16 ConfigError, 16 ConfigError,
@@ -21,104 +21,106 @@ pub enum ErrorType {
21 LibReq, 21 LibReq,
22 LibChrono, 22 LibChrono,
23 LibJson, 23 LibJson,
24 LibIndicatif,
24 IoError, 25 IoError,
25 Other, 26 Other,
26} 27}
27 28
28impl std::error::Error for MLError { 29impl std::error::Error for MLErr {
29 fn description(&self) -> &str { 30 fn description(&self) -> &str {
30 &self.message 31 &self.message
31 } 32 }
32} 33}
33 34
34impl fmt::Display for MLError { 35impl fmt::Display for MLErr {
35 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 36 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
36 match self.etype { 37 match self.etype {
37 ErrorType::ArgumentError => { 38 EType::ArgumentError => {
38 write!(f, "User input not accepted: {}", self.message) 39 write!(f, "User input not accepted: {}", self.message)
39 } 40 }
40 ErrorType::ArgumentCountError => { 41 EType::ArgumentCountError => {
41 write!(f, "Too many/too few arguments") 42 write!(f, "Too many/too few arguments")
42 } 43 }
43 ErrorType::ConfigError => write!(f, "CONFIG"), 44 EType::ConfigError => write!(f, "CONFIG"),
44 ErrorType::DBError => write!(f, "Database: {}", self.message), 45 EType::DBError => write!(f, "Database: {}", self.message),
45 ErrorType::ModError => write!(f, "Mod: {}", self.message), 46 EType::ModError => write!(f, "Mod: {}", self.message),
46 ErrorType::LibToml => write!(f, "TOML"), 47 EType::LibToml => write!(f, "TOML"),
47 ErrorType::LibSql => write!(f, "SQL: {}", self.message), 48 EType::LibSql => write!(f, "SQL: {}", self.message),
48 ErrorType::LibReq => write!(f, "REQWEST"), 49 EType::LibReq => write!(f, "REQWEST"),
49 ErrorType::LibChrono => write!(f, "Chrono error: {}", self.message), 50 EType::LibChrono => write!(f, "Chrono error: {}", self.message),
50 ErrorType::LibJson => write!(f, "JSON: {}", self.message), 51 EType::LibJson => write!(f, "JSON: {}", self.message),
51 ErrorType::IoError => write!(f, "IO"), 52 EType::LibIndicatif => write!(f, "Indicativ: {}", self.message),
52 ErrorType::Other => write!(f, "OTHER"), 53 EType::IoError => write!(f, "IO"),
54 EType::Other => write!(f, "OTHER"),
53 } 55 }
54 } 56 }
55} 57}
56 58
57impl From<reqwest::Error> for MLError { 59impl From<reqwest::Error> for MLErr {
58 fn from(error: reqwest::Error) -> Self { 60 fn from(error: reqwest::Error) -> Self {
59 Self { 61 Self {
60 etype: ErrorType::LibReq, 62 etype: EType::LibReq,
61 message: error.to_string(), 63 message: error.to_string(),
62 } 64 }
63 } 65 }
64} 66}
65 67
66impl From<toml::de::Error> for MLError { 68impl From<toml::de::Error> for MLErr {
67 fn from(error: toml::de::Error) -> Self { 69 fn from(error: toml::de::Error) -> Self {
68 Self { 70 Self {
69 etype: ErrorType::LibToml, 71 etype: EType::LibToml,
70 message: error.to_string(), 72 message: error.to_string(),
71 } 73 }
72 } 74 }
73} 75}
74 76
75impl From<rusqlite::Error> for MLError { 77impl From<rusqlite::Error> for MLErr {
76 fn from(error: rusqlite::Error) -> Self { 78 fn from(error: rusqlite::Error) -> Self {
77 Self { 79 Self {
78 etype: ErrorType::LibSql, 80 etype: EType::LibSql,
79 message: error.to_string(), 81 message: error.to_string(),
80 } 82 }
81 } 83 }
82} 84}
83 85
84impl From<toml::ser::Error> for MLError { 86impl From<toml::ser::Error> for MLErr {
85 fn from(error: toml::ser::Error) -> Self { 87 fn from(error: toml::ser::Error) -> Self {
86 Self { 88 Self {
87 etype: ErrorType::LibToml, 89 etype: EType::LibToml,
88 message: error.to_string(), 90 message: error.to_string(),
89 } 91 }
90 } 92 }
91} 93}
92 94
93impl From<chrono::ParseError> for MLError { 95impl From<chrono::ParseError> for MLErr {
94 fn from(error: chrono::ParseError) -> Self { 96 fn from(error: chrono::ParseError) -> Self {
95 Self { 97 Self {
96 etype: ErrorType::LibChrono, 98 etype: EType::LibChrono,
97 message: error.to_string(), 99 message: error.to_string(),
98 } 100 }
99 } 101 }
100} 102}
101 103
102impl From<std::io::Error> for MLError { 104impl From<std::io::Error> for MLErr {
103 fn from(error: std::io::Error) -> Self { 105 fn from(error: std::io::Error) -> Self {
104 Self { 106 Self {
105 etype: ErrorType::IoError, 107 etype: EType::IoError,
106 message: error.to_string(), 108 message: error.to_string(),
107 } 109 }
108 } 110 }
109} 111}
110 112
111impl From<serde_json::error::Error> for MLError { 113impl From<serde_json::error::Error> for MLErr {
112 fn from(value: serde_json::error::Error) -> Self { 114 fn from(value: serde_json::error::Error) -> Self {
113 Self { 115 Self {
114 etype: ErrorType::LibJson, 116 etype: EType::LibJson,
115 message: value.to_string(), 117 message: value.to_string(),
116 } 118 }
117 } 119 }
118} 120}
119 121
120impl MLError { 122impl MLErr {
121 #[must_use] pub fn new(etype: ErrorType, message: &str) -> Self { 123 #[must_use] pub fn new(etype: EType, message: &str) -> Self {
122 Self { 124 Self {
123 etype, 125 etype,
124 message: String::from(message), 126 message: String::from(message),