From 08681756b63d407204be897b84ecf61a3cd045dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Wed, 27 Sep 2023 14:15:59 +0200 Subject: [PATCH] v0.0.273 add stack to PanicWrappedErr --- goextVersion.go | 4 ++-- langext/panic.go | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/goextVersion.go b/goextVersion.go index 9edb4aa..949083f 100644 --- a/goextVersion.go +++ b/goextVersion.go @@ -1,5 +1,5 @@ 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" diff --git a/langext/panic.go b/langext/panic.go index 084ead2..459dffd 100644 --- a/langext/panic.go +++ b/langext/panic.go @@ -1,7 +1,10 @@ package langext +import "runtime/debug" + type PanicWrappedErr struct { panic any + Stack string } func (p PanicWrappedErr) Error() string { @@ -15,7 +18,7 @@ func (p PanicWrappedErr) ReoveredObj() any { func RunPanicSafe(fn func()) (err error) { defer func() { 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) { defer func() { 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() { if rec := recover(); rec != nil { 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 { r1 = *new(T1) 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) r2 = *new(T2) r3 = *new(T3) - err = PanicWrappedErr{panic: rec} + err = PanicWrappedErr{panic: rec, Stack: string(debug.Stack())} } }()