Skip to content

Commit

Permalink
Merge pull request #137 from felipeap92/feature/update-panic-log
Browse files Browse the repository at this point in the history
Update util Pcal method to log stack trace as a raw string literal
  • Loading branch information
leohahn authored Aug 8, 2020
2 parents c273c1f + b7797d4 commit 42f40cc
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"os"
"reflect"
"runtime/debug"
"strconv"

"github.com/topfreegames/pitaya/conn/message"
"github.com/topfreegames/pitaya/constants"
Expand Down Expand Up @@ -65,9 +66,11 @@ func Pcall(method reflect.Method, args []reflect.Value) (rets interface{}, err e
defer func() {
if rec := recover(); rec != nil {
// Try to use logger from context here to help trace error cause
stackTrace := debug.Stack()
stackTraceAsRawStringLiteral := strconv.Quote(string(stackTrace))
log := getLoggerFromArgs(args)
log.Errorf("panic - pitaya/dispatch: %s: %v", method.Name, rec)
log.Debugf("%s", debug.Stack())
log.Errorf("panic - pitaya/dispatch: methodName=%s panicData=%v stackTrace=%s", method.Name, rec, stackTraceAsRawStringLiteral)

if s, ok := rec.(string); ok {
err = errors.New(s)
} else {
Expand Down

0 comments on commit 42f40cc

Please sign in to comment.