Skip to content

Commit

Permalink
Merge pull request #31 from HRI-EU/error_handling
Browse files Browse the repository at this point in the history
Improve error handling
  • Loading branch information
vjeantet authored Dec 22, 2020
2 parents eaf71a2 + cd7b3c3 commit ed18c75
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions grok.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -229,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 {
Expand Down

0 comments on commit ed18c75

Please sign in to comment.