feat: add Wrap and Wrapf in errorx (#2126)
This commit is contained in:
21
core/errorx/wrap.go
Normal file
21
core/errorx/wrap.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package errorx
|
||||
|
||||
import "fmt"
|
||||
|
||||
// Wrap returns an error that wraps err with given message.
|
||||
func Wrap(err error, message string) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("%s: %w", message, err)
|
||||
}
|
||||
|
||||
// Wrapf returns an error that wraps err with given format and args.
|
||||
func Wrapf(err error, format string, args ...interface{}) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("%s: %w", fmt.Sprintf(format, args...), err)
|
||||
}
|
||||
Reference in New Issue
Block a user