diff options
| author | WriterV2 <primary-v2@protonmail.com> | 2023-06-03 12:56:11 +0200 |
|---|---|---|
| committer | WriterV2 <primary-v2@protonmail.com> | 2023-06-03 12:56:11 +0200 |
| commit | 683ca3627f38461cbbdee321a15821b46e72ae6a (patch) | |
| tree | b24297b68f591d343055fea6226dba7b69905e18 /src/main.rs | |
| parent | 8072e6194d7b77d54ff75f245a5101ea72e5e8a1 (diff) | |
Fix error handling context
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/main.rs b/src/main.rs index 26c3794..4dc6e5e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ -use anyhow::Result; -use tera::{Context, Tera}; +use anyhow::{Context, Ok, Result}; +use tera::Tera; use crate::works::Works; @@ -7,19 +7,25 @@ mod works; fn main() -> Result<()> { // new tera instance - let tera = Tera::new("templates/**/*.html")?; + let tera = Tera::new("templates/**/*.html").context("Failed to create new Tera instance")?; // render index.html file - let context = Context::new(); - let output = tera.render("index.html", &context)?; - std::fs::write("docs/index.html", output)?; + let context = tera::Context::new(); + let output = tera + .render("index.html", &context) + .context("Failed to render index.html")?; + std::fs::write("docs/index.html", output).context("Failed to write index.html")?; // render stories.html file let stories = std::rc::Rc::new(works::stories::Stories::new_from_file( - &std::fs::File::open(std::path::PathBuf::from("stories.json"))?, + &std::fs::File::open(std::path::PathBuf::from("stories.json")) + .context("Failed to open stories.json")?, )?); - std::rc::Rc::clone(&stories).render_overview_page(&tera, "stories")?; - std::rc::Rc::clone(&stories).render_single_pages(&tera, "story")?; - - anyhow::Ok(()) + std::rc::Rc::clone(&stories) + .render_overview_page(&tera, "stories") + .context("Failed to render overview page for stories")?; + std::rc::Rc::clone(&stories) + .render_single_pages(&tera, "story") + .context("Failed to render single pages for stories")?; + Ok(()) } |
