You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
442 B
Go
22 lines
442 B
Go
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 ...any) error {
|
|
if err == nil {
|
|
return nil
|
|
}
|
|
|
|
return fmt.Errorf("%s: %w", fmt.Sprintf(format, args...), err)
|
|
}
|