Skip to content

Commit

Permalink
错误恢复失败时打印堆栈调用信息
Browse files Browse the repository at this point in the history
  • Loading branch information
keepchen committed Mar 1, 2024
1 parent e29c804 commit d96c2eb
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions sail/sail.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package sail

import (
"fmt"
"runtime"
"runtime/debug"
"sync"

"github.com/keepchen/go-sail/v3/lib/etcd"
Expand Down Expand Up @@ -107,6 +110,13 @@ func (f *Framework) SetupApiOption(opt *api.Option) Sailor {
func (f *Framework) Launch(registerRoutes func(ginEngine *gin.Engine)) {
defer func() {
if err := recover(); err != nil {
pc := make([]uintptr, 10)
n := runtime.Callers(3, pc)
frames := runtime.CallersFrames(pc[:n])
frame, _ := frames.Next()
fmt.Printf("[GO-SAIL] Try to recover but failed\nReason: %v\nCaller: %s:%d -> %s\nStack:\n",
err, frame.File, frame.Line, frame.Function)
debug.PrintStack()
logger.GetLogger().Error("---- Recovered ----", zap.Any("error", err))
}
}()
Expand Down Expand Up @@ -199,6 +209,13 @@ func (f *Framework) Hook(registerRoutes func(ginEngine *gin.Engine), beforeFunc,
func (l *Launcher) Launch() {
defer func() {
if err := recover(); err != nil {
pc := make([]uintptr, 10)
n := runtime.Callers(3, pc)
frames := runtime.CallersFrames(pc[:n])
frame, _ := frames.Next()
fmt.Printf("[GO-SAIL] Try to recover but failed\nReason: %v\nCaller: %s:%d -> %s\nStack:\n",
err, frame.File, frame.Line, frame.Function)
debug.PrintStack()
logger.GetLogger().Error("---- Recovered ----", zap.Any("error", err))
}
}()
Expand Down

0 comments on commit d96c2eb

Please sign in to comment.