mirror of
https://github.com/argoproj/argo-cd
synced 2026-04-21 17:07:16 +00:00
20 lines
446 B
Go
20 lines
446 B
Go
package guard
|
|
|
|
import (
|
|
"runtime/debug"
|
|
)
|
|
|
|
// Minimal logger contract; avoids depending on any specific logging package.
|
|
type Logger interface{ Errorf(string, ...any) }
|
|
|
|
// Run executes fn and recovers a panic, logging a component-specific message.
|
|
func RecoverAndLog(fn func(), log Logger, msg string) {
|
|
defer func() {
|
|
if r := recover(); r != nil {
|
|
if log != nil {
|
|
log.Errorf("%s: %v %s", msg, r, debug.Stack())
|
|
}
|
|
}
|
|
}()
|
|
fn()
|
|
}
|