From dd0ad8d538f817797793e43f45cb7cdfca1da662 Mon Sep 17 00:00:00 2001 From: _ <_@_> Date: Thu, 11 Sep 2025 01:14:19 +0000 Subject: [PATCH] fix clippy lints and improve error handling --- README.md | 4 ++++ src/main.rs | 9 +++++++++ src/wac_campfire.rs | 3 ++- src/wac_common_ninja.rs | 3 ++- src/wac_ical.rs | 8 ++++---- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 3fa62d4..0a05a61 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,10 @@ # Run RSS debug tool cargo run -- debug-rss untracked/*.rss + +# Debug the HTML output +# (You may need to run 'auto' mode first to download the ICS files) +cargo run -- debug-output --config config.toml ``` # TODO diff --git a/src/main.rs b/src/main.rs index c766a78..368500e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -348,6 +348,15 @@ fn output_html( } std::fs::create_dir_all("output")?; + { + let temp_path = "output/calendars.html.tmp"; + let final_path = "output/calendars.html"; + let mut f = std::fs::File::create(temp_path)?; + + f.write_all("".as_bytes())?; + std::fs::rename(temp_path, final_path)?; + } + { let temp_path = "output/index.html.tmp"; let final_path = "output/index.html"; diff --git a/src/wac_campfire.rs b/src/wac_campfire.rs index 72af29d..49e26ae 100644 --- a/src/wac_campfire.rs +++ b/src/wac_campfire.rs @@ -110,7 +110,8 @@ impl Calendar { } pub(crate) fn read_from_config(config: Config) -> Result { - let s = std::fs::read_to_string(&config.dl.file_path)?; + let path = &config.dl.file_path; + let s = std::fs::read_to_string(path).with_context(|| format!("Couldn't read {path:?}"))?; Self::read_from_str(config, &s) } } diff --git a/src/wac_common_ninja.rs b/src/wac_common_ninja.rs index f6a668d..05380d2 100644 --- a/src/wac_common_ninja.rs +++ b/src/wac_common_ninja.rs @@ -94,7 +94,8 @@ impl Calendar { } pub(crate) fn read_from_config(config: Config) -> Result { - let s = std::fs::read_to_string(&config.dl.file_path)?; + let path = &config.dl.file_path; + let s = std::fs::read_to_string(path).with_context(|| format!("Couldn't read {path:?}"))?; Self::read_from_str(config, &s) } } diff --git a/src/wac_ical.rs b/src/wac_ical.rs index 6ba5df8..9bebdc2 100644 --- a/src/wac_ical.rs +++ b/src/wac_ical.rs @@ -150,7 +150,7 @@ fn ical_event_instances( vec![dtstart_normalized] }; - let instances = dates + dates .into_iter() .map(|dtstart| { let has_rrule = ev.properties().get("RRULE").is_some(); @@ -179,8 +179,7 @@ fn ical_event_instances( url, }) }) - .collect(); - instances + .collect() } /// Used to link recurrence exceptions to the original events they replace @@ -268,7 +267,8 @@ impl Calendar { } pub(crate) fn read_from_config(config: Config) -> Result { - let s = std::fs::read_to_string(&config.dl.file_path)?; + let path = &config.dl.file_path; + let s = std::fs::read_to_string(path).with_context(|| format!("Couldn't read {path:?}"))?; Self::read_from_str(config, &s) } }