summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcos <cos>2022-07-23 11:12:29 +0200
committercos <cos>2022-07-23 11:12:39 +0200
commit89d023ab82a4b3445b3db81a6346d3d8d9b69dbf (patch)
tree60df7a0a74ce84ae09ccecf4d0f4408d33e5767e
parent958a5eb7221705f07d9d831f7f6f5836e8718a24 (diff)
downloadcph.rs-topic/invitation-mailer.zip
Improve error handling when parsing jekyll inputtopic/invitation-mailer
-rw-r--r--_invitation-mailer/src/main.rs17
1 files changed, 10 insertions, 7 deletions
diff --git a/_invitation-mailer/src/main.rs b/_invitation-mailer/src/main.rs
index 369d6fe..f1ff25f 100644
--- a/_invitation-mailer/src/main.rs
+++ b/_invitation-mailer/src/main.rs
@@ -118,18 +118,21 @@ impl HackNight {
let event = document.select("article.event").iter().next()
.ok_or_else(|| anyhow!("Could not find event in html file"))?;
- let year = event.select("p.event-year").text().to_string().parse::<i32>()?;
- let month = month_number(event.select("p.event-month").text().to_string().as_str())?;
- let day = event.select("p.event-day").text().to_string().parse::<u32>()?;
+ let year = event.select("p.event-year").text().to_string().parse::<i32>()
+ .context("event-year")?;
+ let month = month_number(event.select("p.event-month").text().to_string().as_str())
+ .context("event-month")?;
+ let day = event.select("p.event-day").text().to_string().parse::<u32>()
+ .context("event-day")?;
let timespan = event.select("dl.dl-horizontal > dd").iter().last()
.ok_or_else(|| anyhow!("No venue timespan found"))?.text().to_string();
let (start_str, end_str) = timespan.split_once('—')
.ok_or_else(|| anyhow!("Couldn't split timespan"))?;
- let start_hh = start_str[0..=1].parse::<u32>()?;
- let start_mm = start_str[3..=4].parse::<u32>()?;
- let end_hh: u32 = end_str[0..=1].parse()?;
- let end_mm: u32 = end_str[3..=4].parse()?;
+ let start_hh = start_str[0..=1].parse::<u32>().context("Start hour")?;
+ let start_mm = start_str[3..=4].parse::<u32>().context("Start minute")?;
+ let end_hh: u32 = end_str[0..=1].parse().context("End hour")?;
+ let end_mm: u32 = end_str[3..=4].parse().context("End minute")?;
let description = event.select("div.event-desc");
let title = event.select("h3.event-desc-header").text().to_string().trim().to_owned();