-
If I have custom filter that might produce an use anyhow::Context;
fn format_datetime(_: &State, value: &Value) -> Result<String, minijinja::Error> {
let date = value.to_string() + "Z";
Ok(
date
.parse::<DateTime<Local>>()
.context("Failed to parse date from template")?
.format("%-m/%d/%Y, %-I:%M %p")
.to_string(),
)
.into()
} how do I return that error from the custom filter? Or in other words how can I convert an |
Beta Was this translation helpful? Give feedback.
Answered by
atsmtat
May 19, 2025
Replies: 1 comment 1 reply
-
You can construct a date
.parse::<DateTime<Local>>()
.map_err(|e| minijinja::Error::new(minijinja::ErrorKind::InvalidOperation, &format!("Failed to parse date from template due to: {e}")))?
.format(...) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
RedHatter
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can construct a
minijinja::Error
using https://docs.rs/minijinja/latest/minijinja/struct.Error.html#method.new by picking an appropriateErrorKind
.InvalidOperation
is commonly used in the builtin filters. For example,