Return an error if no valid patterns. (#2753)

This commit is contained in:
Daniel Nelson
2017-05-02 14:54:38 -07:00
committed by GitHub
parent 188703e204
commit f7f1eaef65
3 changed files with 12 additions and 14 deletions

View File

@@ -118,11 +118,18 @@ func (p *Parser) Compile() error {
// Give Patterns fake names so that they can be treated as named
// "custom patterns"
p.namedPatterns = make([]string, len(p.Patterns))
p.namedPatterns = make([]string, 0, len(p.Patterns))
for i, pattern := range p.Patterns {
if pattern == "" {
continue
}
name := fmt.Sprintf("GROK_INTERNAL_PATTERN_%d", i)
p.CustomPatterns += "\n" + name + " " + pattern + "\n"
p.namedPatterns[i] = "%{" + name + "}"
p.namedPatterns = append(p.namedPatterns, "%{"+name+"}")
}
if len(p.namedPatterns) == 0 {
return fmt.Errorf("pattern required")
}
// Combine user-supplied CustomPatterns with DEFAULT_PATTERNS and parse