Skip to content

Commit

Permalink
Return errors applying filters as Render errors
Browse files Browse the repository at this point in the history
  • Loading branch information
thessem committed Jul 21, 2017
1 parent de5fffa commit 8ee8cef
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion expressions/builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ func makeFilter(fn valueFn, name string, args []valueFn) valueFn {
return func(ctx Context) evaluator.Value {
result, err := ctx.ApplyFilter(name, fn, args)
if err != nil {
panic(err)
panic(FilterError{
FilterName: name,
Err: err,
})
}
return evaluator.ValueOf(result)
}
Expand Down
2 changes: 2 additions & 0 deletions expressions/expressions.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ func (e expression) Evaluate(ctx Context) (out interface{}, err error) {
err = e
case UndefinedFilter:
err = e
case FilterError:
err = e
default:
panic(r)
}
Expand Down
10 changes: 10 additions & 0 deletions expressions/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ func (e UndefinedFilter) Error() string {
return fmt.Sprintf("undefined filter %q", string(e))
}

// FilterError is the error returned by a filter when it is applied
type FilterError struct {
FilterName string
Err error
}

func (e FilterError) Error() string {
return fmt.Sprintf("error applying filter %q (%q)", e.FilterName, e.Err)
}

type valueFn func(Context) evaluator.Value

// AddFilter adds a filter to the filter dictionary.
Expand Down

0 comments on commit 8ee8cef

Please sign in to comment.