Improve CatchPanicCallback: extract context early and clarify example

Co-authored-by: warkanum <208308+warkanum@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-12-30 11:07:46 +00:00
parent e10e2e1c27
commit 4cb35a78b0

View File

@@ -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()