summaryrefslogtreecommitdiff
path: root/src/works/stories.rs
diff options
context:
space:
mode:
authorWriterV2 <primary-v2@protonmail.com>2023-02-12 12:42:59 +0100
committerWriterV2 <primary-v2@protonmail.com>2023-02-12 12:42:59 +0100
commit69e9eac947f6f319d3c8889f53da29461ebd6c28 (patch)
tree67ce046ddf3a57507ee7a8144e0c2da52d0cc572 /src/works/stories.rs
parent7d9665520e3461c43e3cc1b4f585ed5bbfd13a32 (diff)
Add missing error context + Remove redundant error handling
Diffstat (limited to 'src/works/stories.rs')
-rw-r--r--src/works/stories.rs28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/works/stories.rs b/src/works/stories.rs
index 8f0cb53..9d061f6 100644
--- a/src/works/stories.rs
+++ b/src/works/stories.rs
@@ -1,3 +1,4 @@
+use anyhow::Context;
use chrono::NaiveDate;
use serde::{Deserialize, Serialize};
@@ -32,39 +33,40 @@ impl super::Works for Stories {
context.insert("story", story);
context.insert("text", &story.get_text()?);
result.push(std::fs::write(
- story.get_html_path()?.as_str(),
+ story.get_html_path().as_str(),
tera_instance.render(format!("{}.html", template_name).as_str(), &context)?,
));
}
}
- Ok(())
+ anyhow::Ok(()).with_context(|| "Failed to render single story pages")
}
}
impl Story {
// check if it's necessary to re-compile the html single page
fn update_available(&self) -> anyhow::Result<bool> {
- Ok(
- // pdf document changes
+ // pdf document changes
+ anyhow::Ok(
std::fs::metadata(format!("docs/stories/{}", &self.path_to_document))?.modified()?
- > std::fs::metadata(self.get_html_path()?)?.modified()?
+ > std::fs::metadata(self.get_html_path())?.modified()?
// base template changes
|| std::fs::metadata("templates/base.html")?.modified()?
- > std::fs::metadata(self.get_html_path()?)?.modified()?
+ > std::fs::metadata(self.get_html_path())?.modified()?
// story template changes
- ||std::fs::metadata("templates/story.html")?.modified()? > std::fs::metadata(self.get_html_path()?)?.modified()?
+ ||std::fs::metadata("templates/story.html")?.modified()? > std::fs::metadata(self.get_html_path())?.modified()?
// HTML file doesn't exist yet
- || !std::path::Path::new(&self.get_html_path()?).exists(),
- )
+ || !std::path::Path::new(&self.get_html_path()).exists()
+ // add error context
+ ).with_context(|| format!("Failed to check for update for {}", self.title))
}
// use story document name for the single page
// e.g. mit_gutem_gewissen.pdf -> mit_gutem_gewissen.html
- fn get_html_path(&self) -> anyhow::Result<String> {
- Ok(format!(
+ fn get_html_path(&self) -> String {
+ format!(
"docs/stories/{}.html",
self.path_to_document.replace(".pdf", "")
- ))
+ )
}
// extract text from pdf document
@@ -91,7 +93,7 @@ impl Story {
.replace_all(&text, " ")
.to_string();
- Ok(text)
+ anyhow::Ok(text).with_context(|| format!("Failed to extract text for {}", self.title))
}
}