From f7a6d2e9c67c1fdf8fc17fa0461a201fd2720537 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Thu, 19 Jan 2023 18:37:42 +0100 Subject: input mostly inplemented, mods missing --- src/error.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/error.rs') diff --git a/src/error.rs b/src/error.rs index dbe7224..a1f5f2e 100644 --- a/src/error.rs +++ b/src/error.rs @@ -15,9 +15,11 @@ pub enum ErrorType { ArgumentCountError, ConfigError, DBError, + ModError, LibToml, LibSql, LibReq, + LibChrono, IoError, Other, } @@ -31,13 +33,15 @@ impl std::error::Error for MLError { impl fmt::Display for MLError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self.etype { - ErrorType::ArgumentError => write!(f, "Wrong argument"), + ErrorType::ArgumentError => write!(f, "User input not accepted: {}", self.message), ErrorType::ArgumentCountError => write!(f, "Too many/too few arguments"), ErrorType::ConfigError => write!(f, "CONFIG"), ErrorType::DBError => write!(f, "DATABASE"), + ErrorType::ModError => write!(f, "Mod: {}", self.message), ErrorType::LibToml => write!(f, "TOML"), ErrorType::LibSql => write!(f, "SQL"), ErrorType::LibReq => write!(f, "REQWEST"), + ErrorType::LibChrono => write!(f, "Chrono error: {}", self.message), ErrorType::IoError => write!(f, "IO"), ErrorType::Other => write!(f, "OTHER") } @@ -68,6 +72,12 @@ impl From for MLError { } } +impl From for MLError { + fn from(error: chrono::ParseError) -> Self { + Self { etype: ErrorType::LibChrono, message: error.to_string() } + } +} + impl From for MLError { fn from(error: std::io::Error) -> Self { Self { etype: ErrorType::IoError, message: error.to_string() } -- cgit v1.2.3