From a555343893601077ace03a2d44abfccc6f92db09 Mon Sep 17 00:00:00 2001 From: wagner riffel Date: Fri, 9 Apr 2021 16:26:09 -0300 Subject: [PATCH] config: proper error handle [filters] config Instead of panic when compiling a regular expression, return it up Signed-off-by: wagner riffel --- config/config.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index 8b409fe..8032201 100644 --- a/config/config.go +++ b/config/config.go @@ -304,7 +304,7 @@ func (config *AercConfig) LoadConfig(file *ini.File) error { filter.Header = strings.ToLower(header) filter.Regex, err = regexp.Compile(regex) if err != nil { - panic(err) + return err } } else if strings.ContainsRune(match, ',') { filter.FilterType = FILTER_HEADER @@ -312,6 +312,9 @@ func (config *AercConfig) LoadConfig(file *ini.File) error { value := filter.Filter[strings.Index(filter.Filter, ",")+1:] filter.Header = strings.ToLower(header) filter.Regex, err = regexp.Compile(regexp.QuoteMeta(value)) + if err != nil { + return err + } } else { filter.FilterType = FILTER_MIMETYPE } -- 2.45.2