mirror of
https://github.com/bitechdev/ResolveSpec.git
synced 2025-12-31 00:34:25 +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
|
||||
// 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() {
|
||||
ctx, _ := extractContext(args...)
|
||||
return func() {
|
||||
ctx, _ := extractContext(args...)
|
||||
if err := recover(); err != nil {
|
||||
callstack := debug.Stack()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user