github.com/argoproj/argo-cd/v3@v3.2.1/util/guard/guard.go (about) 1 package guard 2 3 import ( 4 "runtime/debug" 5 ) 6 7 // Minimal logger contract; avoids depending on any specific logging package. 8 type Logger interface{ Errorf(string, ...any) } 9 10 // Run executes fn and recovers a panic, logging a component-specific message. 11 func RecoverAndLog(fn func(), log Logger, msg string) { 12 defer func() { 13 if r := recover(); r != nil { 14 if log != nil { 15 log.Errorf("%s: %v %s", msg, r, debug.Stack()) 16 } 17 } 18 }() 19 fn() 20 }