From fedb4e7c7ebf21619f89c29d011e288363a978e9 Mon Sep 17 00:00:00 2001 From: Joris Date: Thu, 6 Feb 2025 21:15:32 +0100 Subject: Use anyhow Error --- src/templates.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/templates.rs') 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, String> { +pub fn get() -> Result> { 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); -- cgit v1.2.3