|
|
@ -4,7 +4,6 @@ import (
|
|
|
|
"context"
|
|
|
|
"context"
|
|
|
|
"runtime/debug"
|
|
|
|
"runtime/debug"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/logc"
|
|
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
@ -22,12 +21,13 @@ func Recover(cleanups ...func()) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// RecoverCtx is used with defer to do cleanup on panics.
|
|
|
|
func RecoverCtx(ctx context.Context, cleanups ...func()) {
|
|
|
|
func RecoverCtx(ctx context.Context, cleanups ...func()) {
|
|
|
|
for _, cleanup := range cleanups {
|
|
|
|
for _, cleanup := range cleanups {
|
|
|
|
cleanup()
|
|
|
|
cleanup()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if p := recover(); p != nil {
|
|
|
|
if p := recover(); p != nil {
|
|
|
|
logc.Errorf(ctx, "%+v\n\n%s", p, debug.Stack())
|
|
|
|
logx.WithContext(ctx).Errorf("%+v\n%s", p, debug.Stack())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|