Working Error Logging

This commit is contained in:
Neshura 2023-12-17 22:29:18 +01:00
parent bba7fae8b9
commit 47e6cc59c0
Signed by: Neshura
GPG key ID: B6983AAA6B9A7A6C
7 changed files with 253 additions and 123 deletions
src/post_history

View file

@ -1,5 +1,4 @@
use std::collections::HashMap;
use std::error::Error;
use std::fs;
use std::fs::OpenOptions;
use std::io::Write;
@ -12,10 +11,13 @@ pub(crate) struct SeriesHistory {
}
impl SeriesHistory {
pub(crate) fn load_history() -> Result<Self, Box<dyn Error>> {
pub(crate) fn load_history() -> Result<Self, String> {
match Path::new("history.toml").exists() {
true => {
let file_contents: String = fs::read_to_string("history.toml")?;
let file_contents: String = match fs::read_to_string("history.toml") {
Ok(data) => data,
Err(e) => return Err(format!("{}", e)),
};
let history: Result<SeriesHistory, toml::de::Error> = match file_contents.len() {
0 => return Ok(SeriesHistory {
@ -26,7 +28,7 @@ impl SeriesHistory {
match history {
Ok(data) => Ok(data),
Err(e) => Err(Box::new(e))
Err(e) => Err(format!("{}", e))
}
},
false => {