config: proper error handle [filters] config

Instead of panic when compiling a regular expression, return it up

Signed-off-by: wagner riffel <w@104d.net>
This commit is contained in:
wagner riffel 2021-04-09 16:26:09 -03:00 committed by Reto Brunner
parent 548facab92
commit a555343893
1 changed files with 4 additions and 1 deletions

View File

@ -304,7 +304,7 @@ func (config *AercConfig) LoadConfig(file *ini.File) error {
filter.Header = strings.ToLower(header) filter.Header = strings.ToLower(header)
filter.Regex, err = regexp.Compile(regex) filter.Regex, err = regexp.Compile(regex)
if err != nil { if err != nil {
panic(err) return err
} }
} else if strings.ContainsRune(match, ',') { } else if strings.ContainsRune(match, ',') {
filter.FilterType = FILTER_HEADER filter.FilterType = FILTER_HEADER
@ -312,6 +312,9 @@ func (config *AercConfig) LoadConfig(file *ini.File) error {
value := filter.Filter[strings.Index(filter.Filter, ",")+1:] value := filter.Filter[strings.Index(filter.Filter, ",")+1:]
filter.Header = strings.ToLower(header) filter.Header = strings.ToLower(header)
filter.Regex, err = regexp.Compile(regexp.QuoteMeta(value)) filter.Regex, err = regexp.Compile(regexp.QuoteMeta(value))
if err != nil {
return err
}
} else { } else {
filter.FilterType = FILTER_MIMETYPE filter.FilterType = FILTER_MIMETYPE
} }