Skip to content

Commit

Permalink
fix(errors): List alternative filters
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `Context::get_filter` now returns `Result`.
  • Loading branch information
epage committed Nov 20, 2018
1 parent 3acaba6 commit 406187b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
17 changes: 12 additions & 5 deletions liquid-interpreter/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,18 @@ impl<'g> Context<'g> {
}

/// Grab a `FilterValue`.
pub fn get_filter<'b>(&'b self, name: &str) -> Option<&'b FilterValue> {
self.filters.get(name).map(|f| {
let f: &FilterValue = f;
f
})
pub fn get_filter<'b>(&'b self, name: &str) -> Result<&'b FilterValue> {
self.filters
.get(name)
.map(|f| {
let f: &FilterValue = f;
f
}).ok_or_else(|| {
let available = itertools::join(self.filters.keys(), ", ");
Error::with_msg("Unknown filter")
.context("requested filter", name.to_owned())
.context("available filters", available)
})
}

/// Access the block's `InterruptState`.
Expand Down
6 changes: 2 additions & 4 deletions liquid-interpreter/src/filter_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::io::Write;

use itertools;

use error::{Error, Result, ResultLiquidChainExt, ResultLiquidExt};
use error::{Result, ResultLiquidChainExt, ResultLiquidExt};
use value::Value;

use super::Context;
Expand Down Expand Up @@ -58,9 +58,7 @@ impl FilterChain {

// apply all specified filters
for filter in &self.filters {
let f = context.get_filter(&filter.name).ok_or_else(|| {
Error::with_msg("Unsupported filter").context("filter", filter.name.clone())
})?;
let f = context.get_filter(&filter.name)?;

let arguments: Result<Vec<Value>> = filter
.arguments
Expand Down

0 comments on commit 406187b

Please sign in to comment.