Skip to content

Commit

Permalink
feat: panic message
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangliang committed Feb 3, 2023
1 parent 15262c5 commit 0f98ba9
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion pkg/agent/subscriber.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package agent

import (
"bytes"
"encoding/json"
"fmt"
"runtime"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -185,7 +187,7 @@ func (g *GqlSubscriber) recoverPanic(name string, tick Ticker) {
outcome.Name = name
outcome.Class = transfer.CLASS_EVENT
outcome.Status = transfer.STATUS_ERROR
outcome.Err = fmt.Sprintf("receive panic: %v", r)
outcome.Err = fmt.Sprintf("receive panic: %v \n", PanicMessage(r))
tick.actorCtx().Send(tick.stat(), &outcome)
log.Error("event panic", zap.String("event", name), zap.String("task", tick.GetTree().GetTitile()), zap.Error(fmt.Errorf("panic: %v", r)))
}
Expand Down Expand Up @@ -229,3 +231,16 @@ func NewGqlRawSubscriber(name, query string) *GqlSubscriber {
}
return subscriber
}

func PanicMessage(err interface{}) string {
buf := new(bytes.Buffer)
fmt.Fprintf(buf, "%v\n", err)
for i := 1;; i ++ {
_, file, line, ok := runtime.Caller(i)
if !ok {
break
}
fmt.Fprintf(buf, "%s:%d\n", file, line)
}
return buf.String()
}

0 comments on commit 0f98ba9

Please sign in to comment.