chore: add more tests (#3229)

This commit is contained in:
Kevin Wan
2023-05-08 23:49:13 +08:00
committed by GitHub
parent 851a72f1cc
commit 93124329ac
2 changed files with 17 additions and 2 deletions

View File

@@ -4,7 +4,6 @@ import (
"context"
"runtime/debug"
"github.com/zeromicro/go-zero/core/logc"
"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()) {
for _, cleanup := range cleanups {
cleanup()
}
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())
}
}