From e4eb8d25f75f016688267808d42f18e84ee2286a Mon Sep 17 00:00:00 2001 From: Sebastian Moser Date: Fri, 17 Mar 2023 07:13:08 +0100 Subject: [PATCH] actually get the error by code from ERRORS and not just returning the same for every error code --- src/error.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/error.rs b/src/error.rs index 4f49154..7cb4dbd 100644 --- a/src/error.rs +++ b/src/error.rs @@ -95,13 +95,19 @@ impl MizeError { pub fn new(code: u32) -> MizeError { let caller_location = std::panic::Location::caller(); - MizeError { - category: "error with error system".to_string(), - code: 114, - message: "The error with code {} was not found in the Errors that where imported from the errors.toml file at build time.".to_string(), - extra_msg: None, - caused_by_msg: None, - code_location: Some(caller_location.into()), + if let Some(err_ref) = ERRORS.get(&code) { + let mut err = err_ref.clone(); + err.code_location = Some(caller_location.into()); + return err; + } else { + return MizeError { + category: "error with error system".to_string(), + code: 114, + message: format!("The error with code {} was not found in the Errors that where imported from the errors.toml file at build time.", code), + extra_msg: None, + caused_by_msg: None, + code_location: Some(caller_location.into()), + }; } } @@ -187,3 +193,5 @@ impl From for MizeError { } + +