From 89193143f90e1b8cbb91445d14942fa39509acbb Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Mon, 9 Jan 2023 23:12:52 +0100 Subject: implemented more Error (dumb) --- src/error.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/error.rs') diff --git a/src/error.rs b/src/error.rs index 192aa76..dbe7224 100644 --- a/src/error.rs +++ b/src/error.rs @@ -14,8 +14,12 @@ pub enum ErrorType { ArgumentError, ArgumentCountError, ConfigError, + DBError, LibToml, + LibSql, + LibReq, IoError, + Other, } impl std::error::Error for MLError { @@ -30,18 +34,34 @@ impl fmt::Display for MLError { ErrorType::ArgumentError => write!(f, "Wrong argument"), ErrorType::ArgumentCountError => write!(f, "Too many/too few arguments"), ErrorType::ConfigError => write!(f, "CONFIG"), + ErrorType::DBError => write!(f, "DATABASE"), ErrorType::LibToml => write!(f, "TOML"), - ErrorType::IoError => write!(f, "IO") + ErrorType::LibSql => write!(f, "SQL"), + ErrorType::LibReq => write!(f, "REQWEST"), + ErrorType::IoError => write!(f, "IO"), + ErrorType::Other => write!(f, "OTHER") } } } +impl From for MLError { + fn from(error: reqwest::Error) -> Self { + Self { etype: ErrorType::LibReq, message: error.to_string() } + } +} + impl From for MLError { fn from(error: toml::de::Error) -> Self { Self { etype: ErrorType::LibToml, message: error.to_string() } } } +impl From for MLError { + fn from(error: rusqlite::Error) -> Self { + Self { etype: ErrorType::LibSql, message: error.to_string() } + } +} + impl From for MLError { fn from(error: toml::ser::Error) -> Self { Self { etype: ErrorType::LibToml, message: error.to_string() } -- cgit v1.2.3