From 2dad184dcfe2f74c971860822004399c1ec92fbc Mon Sep 17 00:00:00 2001 From: Ian Fijolek Date: Fri, 28 Jan 2022 09:53:21 -0800 Subject: [PATCH] More graceful handling of bad match functions --- config.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/config.go b/config.go index 63305d8..c40173d 100644 --- a/config.go +++ b/config.go @@ -51,12 +51,18 @@ func MakeMatchFunc(rule string) MatchFunc { "hostname": dest.Hostname(), "url": dest, } - matchFunc, err := expr.Eval(rule, env) + matchFuncExpr, err := expr.Eval(rule, env) if err != nil { - panic(err) + fmt.Printf("Error evaluating rule %s: %v", rule, err) + return false } - return matchFunc.(MatchFunc)(dest) + matchFunc, ok := matchFuncExpr.(MatchFunc) + if !ok { + fmt.Printf("Error evaluating rule %s. Did not evaluate to a MatchFunc.", rule) + return false + } + return matchFunc(dest) } }