2019-04-23 04:50:31 -05:00
|
|
|
package errutil
|
|
|
|
|
2019-05-15 05:20:17 -05:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
2019-04-23 04:50:31 -05:00
|
|
|
|
2020-07-31 02:45:20 -05:00
|
|
|
// Wrap is a simple wrapper around fmt.Errorf that wraps errors.
|
2019-04-23 04:50:31 -05:00
|
|
|
func Wrap(message string, err error) error {
|
2019-05-15 05:20:17 -05:00
|
|
|
if err == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-07-31 02:45:20 -05:00
|
|
|
return fmt.Errorf("%v: %w", message, err)
|
2019-04-23 04:50:31 -05:00
|
|
|
}
|
2019-05-15 05:20:17 -05:00
|
|
|
|
2020-07-31 02:45:20 -05:00
|
|
|
// Wrapf is a simple wrapper around fmt.Errorf that wraps errors.
|
2019-05-15 05:20:17 -05:00
|
|
|
// Wrapf allows you to send a format and args instead of just a message.
|
|
|
|
func Wrapf(err error, message string, a ...interface{}) error {
|
|
|
|
if err == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return Wrap(fmt.Sprintf(message, a...), err)
|
|
|
|
}
|