mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2026-01-05 11:24:26 +00:00
Improve CatchPanicCallback: extract context early and clarify example
Co-authored-by: warkanum <208308+warkanum@users.noreply.github.com>
This commit is contained in:
@@ -149,10 +149,10 @@ func Debug(template string, args ...interface{}) {
|
|||||||
|
|
||||||
// CatchPanic - Handle panic
|
// CatchPanic - Handle panic
|
||||||
// Returns a function that should be deferred to catch panics
|
// Returns a function that should be deferred to catch panics
|
||||||
// Example usage: defer CatchPanicCallback("MyFunction", callback)()
|
// Example usage: defer CatchPanicCallback("MyFunction", func(err any) { /* cleanup */ })()
|
||||||
func CatchPanicCallback(location string, cb func(err any), args ...interface{}) func() {
|
func CatchPanicCallback(location string, cb func(err any), args ...interface{}) func() {
|
||||||
return func() {
|
|
||||||
ctx, _ := extractContext(args...)
|
ctx, _ := extractContext(args...)
|
||||||
|
return func() {
|
||||||
if err := recover(); err != nil {
|
if err := recover(); err != nil {
|
||||||
callstack := debug.Stack()
|
callstack := debug.Stack()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user