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/works/mod.rs | |
| parent | 18853a2baf20017e926e4bb465e3c02bb5a7af97 (diff) | |
Add anyhow error handling
Diffstat (limited to 'src/works/mod.rs')
| -rw-r--r-- | src/works/mod.rs | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/src/works/mod.rs b/src/works/mod.rs index f062565..cfd302d 100644 --- a/src/works/mod.rs +++ b/src/works/mod.rs @@ -1,18 +1,16 @@ +use anyhow::Result; use serde::{Deserialize, Serialize}; pub mod stories; pub trait Works: for<'a> Deserialize<'a> + Serialize { - fn new_from_file(file: std::fs::File) -> Self { - match serde_json::from_reader(std::io::BufReader::new(file)) { - Ok(work) => work, - Err(err) => panic!("Trying to create work from JSON File - {:?}", err), - } + fn new_from_file(file: std::fs::File) -> Result<Self> { + Ok(serde_json::from_reader(std::io::BufReader::new(file))?) } - fn create_tera_context(&self) -> tera::Context { + fn create_tera_context(&self) -> Result<tera::Context> { let mut context = tera::Context::new(); context.insert("works", &self); - context + Ok(context) } } |
