Add variation of panicWrap that does not take in a context
This commit is contained in:
17
util.go
17
util.go
@@ -19,7 +19,22 @@ func defaul[T comparable](value, def T) T {
|
||||
return value
|
||||
}
|
||||
|
||||
func panicWrap(ctx context.Context, f func (context.Context) error) (err error) {
|
||||
func panicWrap(f func() error) (err error) {
|
||||
defer func () {
|
||||
if pan := recover(); pan != nil {
|
||||
if panErr, ok := pan.(error); ok {
|
||||
err = panErr
|
||||
} else {
|
||||
err = errors.New(fmt.Sprint(pan))
|
||||
}
|
||||
}
|
||||
} ()
|
||||
|
||||
err = f()
|
||||
return
|
||||
}
|
||||
|
||||
func panicWrapCtx(ctx context.Context, f func(context.Context) error) (err error) {
|
||||
defer func () {
|
||||
if pan := recover(); pan != nil {
|
||||
if panErr, ok := pan.(error); ok {
|
||||
|
||||
Reference in New Issue
Block a user