Print stack trace when actors panic
This commit is contained in:
parent
461d0b77e9
commit
4f4c7a0627
25
util.go
25
util.go
@ -12,6 +12,19 @@ import "strings"
|
||||
import "context"
|
||||
import "sync/atomic"
|
||||
import "unicode/utf8"
|
||||
import "runtime/debug"
|
||||
|
||||
func panicErr(message any, stack []byte) (err error) {
|
||||
if panErr, ok := message.(error); ok {
|
||||
err = panErr
|
||||
} else {
|
||||
err = errors.New(fmt.Sprint(message))
|
||||
}
|
||||
if stack != nil {
|
||||
err = fmt.Errorf("%w: %s", err, stack)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func defaul[T comparable](value, def T) T {
|
||||
var zero T
|
||||
@ -22,11 +35,7 @@ func defaul[T comparable](value, def T) T {
|
||||
func panicWrap(f func() error) (err error) {
|
||||
defer func () {
|
||||
if pan := recover(); pan != nil {
|
||||
if panErr, ok := pan.(error); ok {
|
||||
err = panErr
|
||||
} else {
|
||||
err = errors.New(fmt.Sprint(pan))
|
||||
}
|
||||
err = panicErr(pan, debug.Stack())
|
||||
}
|
||||
} ()
|
||||
|
||||
@ -37,11 +46,7 @@ func panicWrap(f func() error) (err error) {
|
||||
func panicWrapCtx(ctx context.Context, f func(context.Context) error) (err error) {
|
||||
defer func () {
|
||||
if pan := recover(); pan != nil {
|
||||
if panErr, ok := pan.(error); ok {
|
||||
err = panErr
|
||||
} else {
|
||||
err = errors.New(fmt.Sprint(pan))
|
||||
}
|
||||
err = panicErr(pan, debug.Stack())
|
||||
}
|
||||
} ()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user