diff options
| author | WriterV2 <primary-v2@protonmail.com> | 2022-09-03 20:01:18 +0200 |
|---|---|---|
| committer | WriterV2 <primary-v2@protonmail.com> | 2022-09-03 20:01:18 +0200 |
| commit | 9d2a896f0180e82d3728c5961c1312502100e69c (patch) | |
| tree | c608e55e78171656687b2a3b968d1b4d624d5ee4 /src/main.rs | |
| parent | 18853a2baf20017e926e4bb465e3c02bb5a7af97 (diff) | |
Add anyhow error handling
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 38 |
1 files changed, 10 insertions, 28 deletions
diff --git a/src/main.rs b/src/main.rs index 7f658ef..4af487e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,42 +1,24 @@ +use anyhow::Result; use tera::{Context, Tera}; use crate::works::Works; mod works; -fn main() { - let tera = match Tera::new("templates/**/*.html") { - Ok(t) => t, - Err(e) => { - println!("Parsing error(s): {}", e); - ::std::process::exit(1); - } - }; +fn main() -> Result<()> { + let tera = Tera::new("templates/**/*.html")?; let context = Context::new(); - let output = tera - .render("index.html", &context) - .expect("Failed to render index.html"); + let output = tera.render("index.html", &context)?; - std::fs::write("docs/index.html", output) - .expect("Failed to write rendered output to index.html"); - - let file = match std::fs::File::open(std::path::PathBuf::from("stories.json")) { - Ok(file) => file, - Err(err) => panic!("Trying to open stories.json in readmode - {:?}", err), - }; + std::fs::write("docs/index.html", output)?; + let file = std::fs::File::open(std::path::PathBuf::from("stories.json"))?; let stories = works::stories::Stories::new_from_file(file); - println!("Stories: {:?}\n", stories); - - let context = stories.create_tera_context(); - println!("Context: {:?}\n", context); - - let stories_html_output = tera - .render("stories.html", &context) - .expect("Failed to render stories.html"); + let context = stories?.create_tera_context(); - std::fs::write("docs/stories.html", stories_html_output) - .expect("Failed to write rendered output to stories.html"); + let stories_html_output = tera.render("stories.html", &context?)?; + std::fs::write("docs/stories.html", stories_html_output)?; + Ok(()) } |
