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
+3 -3
View File
@@ -63,15 +63,15 @@ pub fn character_parse(archive: &mut ZipArchive<File>)
{
// Get the JSON file to a string
let mut characters_file = archive.by_name("characters.json")
.map_err (|err| format!("Unable to read story file: {err}"))?;
.map_err (|err| format!("Unable to read character file: {err}"))?;
let mut file_contents = String::new();
characters_file.read_to_string(&mut file_contents)
.map_err (|err| format!("Unable to read story file to string: {err}"))?;
.map_err (|err| format!("Unable to read character file to string: {err}"))?;
// Serialise this to a HashMap
let characters: HashMap<String, Character> =
serde_json::from_str(&file_contents)
.expect("JSON was not well-formatted");
.map_err (|err| format!("Invalid JSON in characters.json: {err}"))?;
debug!("{characters:?}");
Ok(Arc::new(Mutex::new(characters)))
}