summaryrefslogtreecommitdiff
path: root/src/works
diff options
context:
space:
mode:
authorWriterV2 <primary-v2@protonmail.com>2022-09-03 20:01:18 +0200
committerWriterV2 <primary-v2@protonmail.com>2022-09-03 20:01:18 +0200
commit9d2a896f0180e82d3728c5961c1312502100e69c (patch)
treec608e55e78171656687b2a3b968d1b4d624d5ee4 /src/works
parent18853a2baf20017e926e4bb465e3c02bb5a7af97 (diff)
Add anyhow error handling
Diffstat (limited to 'src/works')
-rw-r--r--src/works/mod.rs12
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)
}
}