Skip to content

Commit

Permalink
fix: recover crashing function
Browse files Browse the repository at this point in the history
relates to #2058
  • Loading branch information
JanDeDobbeleer committed Apr 27, 2022
1 parent 0a8b97b commit d310ea6
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/environment/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,21 @@ func (env *ShellEnvironment) TemplateCache() *TemplateCache {
return tmplCache
}

func (env *ShellEnvironment) DirMatchesOneOf(dir string, regexes []string) bool {
return dirMatchesOneOf(dir, env.Home(), env.GOOS(), regexes)
func (env *ShellEnvironment) DirMatchesOneOf(dir string, regexes []string) (match bool) {
// sometimes the function panics inside golang, we want to silence that error
// and assume that there's no match. Not perfect, but better than crashing
// for the time being until we figure out what the actual root cause is
defer func() {
if err := recover(); err != nil {
message := fmt.Sprintf("%s", err)
env.log(Error, "DirMatchesOneOf", message)
match = false
}
}()
env.lock.Lock()
defer env.lock.Unlock()
match = dirMatchesOneOf(dir, env.Home(), env.GOOS(), regexes)
return
}

func dirMatchesOneOf(dir, home, goos string, regexes []string) bool {
Expand Down

0 comments on commit d310ea6

Please sign in to comment.