Fix: properly handle recover in nested defer functions

This commit is contained in:
divinerapier 2025-11-28 10:14:40 +08:00
parent e54fa18283
commit 9a620e97bc
No known key found for this signature in database
GPG Key ID: 18615A772E240111

14
main.go
View File

@ -45,14 +45,12 @@ func main() {
l.Close()
}()
defer func() {
defer func() {
if err := recover(); err != nil {
l.Error("Panic: %v", err)
buf := make([]byte, 1024)
n := runtime.Stack(buf, false)
l.Error("Stack trace: \n%s", buf[:n])
}
}()
if err := recover(); err != nil {
l.Error("Panic: %v", err)
buf := make([]byte, 1024)
n := runtime.Stack(buf, false)
l.Error("Stack trace: \n%s", buf[:n])
}
}()
logger.InitLogger(config.GetLogLevel(), config.GetLogFile())