v0.0.273 add stack to PanicWrappedErr
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m9s

This commit is contained in:
Mike Schwörer 2023-09-27 14:15:59 +02:00
parent 64772d0474
commit 08681756b6
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
2 changed files with 10 additions and 7 deletions

View File

@ -1,5 +1,5 @@
package goext package goext
const GoextVersion = "0.0.272" const GoextVersion = "0.0.273"
const GoextVersionTimestamp = "2023-09-26T14:41:15+0200" const GoextVersionTimestamp = "2023-09-27T14:15:59+0200"

View File

@ -1,7 +1,10 @@
package langext package langext
import "runtime/debug"
type PanicWrappedErr struct { type PanicWrappedErr struct {
panic any panic any
Stack string
} }
func (p PanicWrappedErr) Error() string { func (p PanicWrappedErr) Error() string {
@ -15,7 +18,7 @@ func (p PanicWrappedErr) ReoveredObj() any {
func RunPanicSafe(fn func()) (err error) { func RunPanicSafe(fn func()) (err error) {
defer func() { defer func() {
if rec := recover(); rec != nil { if rec := recover(); rec != nil {
err = PanicWrappedErr{panic: rec} err = PanicWrappedErr{panic: rec, Stack: string(debug.Stack())}
} }
}() }()
@ -27,7 +30,7 @@ func RunPanicSafe(fn func()) (err error) {
func RunPanicSafeR1(fn func() error) (err error) { func RunPanicSafeR1(fn func() error) (err error) {
defer func() { defer func() {
if rec := recover(); rec != nil { if rec := recover(); rec != nil {
err = PanicWrappedErr{panic: rec} err = PanicWrappedErr{panic: rec, Stack: string(debug.Stack())}
} }
}() }()
@ -38,7 +41,7 @@ func RunPanicSafeR2[T1 any](fn func() (T1, error)) (r1 T1, err error) {
defer func() { defer func() {
if rec := recover(); rec != nil { if rec := recover(); rec != nil {
r1 = *new(T1) r1 = *new(T1)
err = PanicWrappedErr{panic: rec} err = PanicWrappedErr{panic: rec, Stack: string(debug.Stack())}
} }
}() }()
@ -50,7 +53,7 @@ func RunPanicSafeR3[T1 any, T2 any](fn func() (T1, T2, error)) (r1 T1, r2 T2, er
if rec := recover(); rec != nil { if rec := recover(); rec != nil {
r1 = *new(T1) r1 = *new(T1)
r2 = *new(T2) r2 = *new(T2)
err = PanicWrappedErr{panic: rec} err = PanicWrappedErr{panic: rec, Stack: string(debug.Stack())}
} }
}() }()
@ -63,7 +66,7 @@ func RunPanicSafeR4[T1 any, T2 any, T3 any](fn func() (T1, T2, T3, error)) (r1 T
r1 = *new(T1) r1 = *new(T1)
r2 = *new(T2) r2 = *new(T2)
r3 = *new(T3) r3 = *new(T3)
err = PanicWrappedErr{panic: rec} err = PanicWrappedErr{panic: rec, Stack: string(debug.Stack())}
} }
}() }()