Skip to content

Commit

Permalink
opt: use runtime/debug.Stack() to print stack trace of panic (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
coticom committed Mar 26, 2024
1 parent 043c2e9 commit f9d2026
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions cron/chain.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package cron

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

Expand Down Expand Up @@ -45,14 +44,7 @@ func Recover(logger dlog.Logger) JobWrapper {
return FuncJob(func() {
defer func() {
if r := recover(); r != nil {
const size = 64 << 10
buf := make([]byte, size)
buf = buf[:runtime.Stack(buf, false)]
err, ok := r.(error)
if !ok {
err = fmt.Errorf("%v", r)
}
logger.Errorf("panic: stack %v\n%v\n", err, string(buf))
logger.Errorf("panic: stack %v\n%s\n", r, debug.Stack())
}
}()
j.Run()
Expand Down

0 comments on commit f9d2026

Please sign in to comment.