removed unwraps and added a method to Results called .unwrap_or_exit(error_message, error_code)

This tries to unwrap and if it can't then it outputs the error message with the error!() macro
(log library) and exits with the error code.  This is to be used instead of expect and is for
fatal errors
This commit is contained in:
2026-05-15 19:19:17 +01:00
parent a5a45fa1f0
commit 20174e697c
9 changed files with 69 additions and 32 deletions
+4 -3
View File
@@ -4,6 +4,7 @@ use crate::
// Internal code
character,
api,
UnwrapOrExit,
//Libs
Mutex,
Arc,
@@ -43,7 +44,7 @@ pub fn character_parse
{
debug!("{output_string}");
sum_index += counter;
let mut data = data_to_send.lock().unwrap();
let mut data = data_to_send.lock().unwrap_or_exit("Data to send Mutex was poisoned", 2);
data.action_type = String::from("output");
data.content = output_string;
data.character = character_name;
@@ -68,12 +69,12 @@ pub fn character_parse
None => return Err(("Unable to parse property to change character".to_string(),sum_index)),
};
info!("CHANGE command with character {character_name} feature {feature}");
let mut characters = characters.lock().expect("Data cannot be unlocked");
let mut characters = characters.lock().unwrap_or_exit("Character Mutex was poisoned",3);
if let Some(character) = characters.get_mut(&character_name)
&& character.set_field(feature, &output_string)
.is_err() { warn!("Feature {feature} does not exist") }
drop(characters);
let mut data = data_to_send.lock().unwrap(); // TODO eh?
let mut data = data_to_send.lock().unwrap_or_exit("Data to send Mutex was poisoned",2); // TODO eh?
data.action_type = String::from("change");
data.content = String::new();
data.character = character_name;