From d310ea6b890345941b204b6ed35719c760d4dba0 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Wed, 27 Apr 2022 21:24:31 +0200 Subject: [PATCH] fix: recover crashing function relates to #2058 --- src/environment/shell.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/environment/shell.go b/src/environment/shell.go index 9ca33104..c802ab83 100644 --- a/src/environment/shell.go +++ b/src/environment/shell.go @@ -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 {