From f2730a8eaf5849c2e739d7b8bc13d8fa4c25ba5c Mon Sep 17 00:00:00 2001 From: Neshura Date: Sat, 30 Dec 2023 00:28:10 +0100 Subject: [PATCH] Move post_history module out of subdir, port logging from tui to println/journald --- src/{post_history/mod.rs => post_history.rs} | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) rename src/{post_history/mod.rs => post_history.rs} (88%) diff --git a/src/post_history/mod.rs b/src/post_history.rs similarity index 88% rename from src/post_history/mod.rs rename to src/post_history.rs index a1c8e68..3d0e245 100644 --- a/src/post_history/mod.rs +++ b/src/post_history.rs @@ -4,6 +4,7 @@ use std::fs::OpenOptions; use std::io::Write; use std::path::Path; use serde_derive::{Deserialize, Serialize}; +use crate::write_error; #[derive(Serialize, Deserialize, Clone, Debug)] pub(crate) struct SeriesHistory { @@ -11,7 +12,7 @@ pub(crate) struct SeriesHistory { } impl SeriesHistory { - pub(crate) fn load_history() -> Result { + pub(crate) fn load_history() -> Result { let path = confy::get_configuration_file_path(env!("CARGO_PKG_NAME"), "config").expect("Something went wrong with confy"); let config_dir = path.parent().expect("Something went wrong with confy"); @@ -21,7 +22,11 @@ impl SeriesHistory { true => { let file_contents: String = match fs::read_to_string("history.toml") { Ok(data) => data, - Err(e) => return Err(format!("{}", e)), + Err(e) => { + let err_msg = format!("{e}"); + write_error(err_msg); + return Err(()) + }, }; let history: Result = match file_contents.len() { @@ -33,7 +38,11 @@ impl SeriesHistory { match history { Ok(data) => Ok(data), - Err(e) => Err(format!("{}", e)) + Err(e) => { + let err_msg = format!("{e}"); + write_error(err_msg); + Err(()) + } } }, false => {