From 2cea90d007238e569dd26679f0f3ba6c796eb286 Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Thu, 10 Dec 2020 09:00:36 +0100 Subject: [PATCH 1/2] Check returned errors. --- grok.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/grok.go b/grok.go index 31531dc..cf625c4 100644 --- a/grok.go +++ b/grok.go @@ -71,7 +71,10 @@ func NewWithConfig(config *Config) (*Grok, error) { } if !config.SkipDefaultPatterns { - g.AddPatternsFromMap(patterns) + err := g.AddPatternsFromMap(patterns) + if err != nil { + return nil, err + } } if len(config.PatternsDir) > 0 { @@ -108,8 +111,7 @@ func (g *Grok) AddPattern(name, pattern string) error { defer g.patternsGuard.Unlock() g.rawPattern[name] = pattern - g.buildPatterns() - return nil + return g.buildPatterns() } // AddPatternsFromMap loads a map of named patterns @@ -143,7 +145,10 @@ func (g *Grok) addPatternsFromMap(m map[string]string) error { } order, _ := sortGraph(patternDeps) for _, key := range reverseList(order) { - g.addPattern(key, m[key]) + err := g.addPattern(key, m[key]) + if err != nil { + return fmt.Errorf("cannot add pattern %q: %v", key, err) + } } return nil From cd7b3c335edd7314834535fb37c634149cff39ec Mon Sep 17 00:00:00 2001 From: Sven Rebhan Date: Thu, 10 Dec 2020 09:04:08 +0100 Subject: [PATCH 2/2] Fix typo. --- grok.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grok.go b/grok.go index cf625c4..9036161 100644 --- a/grok.go +++ b/grok.go @@ -234,7 +234,7 @@ func (g *Grok) Parse(pattern, text string) (map[string]string, error) { return g.compiledParse(gr, text) } -// ParseTyped returns a inteface{} map with typed captured fields based on provided pattern over the text +// ParseTyped returns a interface{} map with typed captured fields based on provided pattern over the text func (g *Grok) ParseTyped(pattern string, text string) (map[string]interface{}, error) { gr, err := g.compile(pattern) if err != nil {