Skip to content

Commit

Permalink
handle invalid regex patterns. close #2
Browse files Browse the repository at this point in the history
  • Loading branch information
ezekg committed Nov 23, 2015
1 parent f19be0c commit 049acba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion hound.go
Expand Up @@ -85,7 +85,7 @@ func (h *Hound) Sniff(fileName string, hunk *diff.Hunk, warnc chan string, failc
func (h *Hound) Match(pattern string, subject []byte) bool {
r, err := regexp.Compile(pattern)
if err != nil {
return false
panic(err)
}

return r.Match(subject)
Expand Down
10 changes: 9 additions & 1 deletion main.go
Expand Up @@ -48,7 +48,15 @@ func main() {
hunks := fileDiff.GetHunks()

for _, hunk := range hunks {
go hound.Sniff(fileName, hunk, warnc, failc, donec)
go func(hunk *diff.Hunk) {
defer func() {
if r := recover(); r != nil {
fmt.Print(color.RedString(fmt.Sprintf("%s\n", r)))
os.Exit(1)
}
}()
hound.Sniff(fileName, hunk, warnc, failc, donec)
}(hunk)
hunkCount++
}
}
Expand Down

0 comments on commit 049acba

Please sign in to comment.