aboutsummaryrefslogtreecommitdiff
path: root/src/templates.rs
diff options
context:
space:
mode:
authorJoris2025-02-06 21:15:32 +0100
committerJoris2025-02-06 21:15:32 +0100
commitfedb4e7c7ebf21619f89c29d011e288363a978e9 (patch)
treea1caf36b68fc672bf8bc0740ee05dbb6770d02a6 /src/templates.rs
parent2956aa5f5324e4183dbc87f81fbc71fd0f43dbf9 (diff)
Use anyhow Error
Diffstat (limited to 'src/templates.rs')
-rw-r--r--src/templates.rs18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/templates.rs b/src/templates.rs
index ebe8831..f6f4e62 100644
--- a/src/templates.rs
+++ b/src/templates.rs
@@ -1,3 +1,4 @@
+use anyhow::{Error, Result};
use std::fs;
use crate::queries;
@@ -11,21 +12,26 @@ pub enum Header {
Statistics,
}
-pub fn get() -> Result<minijinja::Environment<'static>, String> {
+pub fn get() -> Result<minijinja::Environment<'static>> {
let mut env = minijinja::Environment::new();
for path in read_files_recursive("templates") {
let path = path
.to_str()
- .ok_or("Error getting string of path: {path:?}")?
+ .ok_or(Error::msg("Error getting string of path: {path:?}"))?
.to_string();
- let content = fs::read_to_string(&path)
- .map_err(|_| "Error reading template {path}")?;
+ let content = fs::read_to_string(&path).map_err(|err| {
+ Error::msg(format!("Error reading template {path}: {err}"))
+ })?;
let path_without_prefix = path
.strip_prefix("templates/")
- .ok_or("Error removing prefix from template path")?
+ .ok_or(Error::msg("Error removing prefix from template path"))?
.to_string();
env.add_template_owned(path_without_prefix, content)
- .map_err(|_| "Error adding template {path} to environment")?;
+ .map_err(|err| {
+ Error::msg(format!(
+ "Error adding template {path} to environment: {err}"
+ ))
+ })?;
}
env.add_function("payments_params", payments_params);