2020-12-25 11:14:01 +00:00
|
|
|
package errors
|
|
|
|
|
|
|
|
import (
|
2021-01-05 19:50:39 +00:00
|
|
|
"errors"
|
2020-12-25 11:14:01 +00:00
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2020-12-26 15:53:04 +00:00
|
|
|
func Wrapperf(format string, args ...interface{}) func(error) error {
|
|
|
|
return Wrapper(fmt.Sprintf(format, args...))
|
|
|
|
}
|
|
|
|
|
2020-12-25 11:14:01 +00:00
|
|
|
func Wrapper(msg string) func(error) error {
|
|
|
|
return func(err error) error {
|
|
|
|
return Wrap(err, msg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-26 15:53:04 +00:00
|
|
|
func Wrapf(err error, format string, args ...interface{}) error {
|
|
|
|
return Wrap(err, fmt.Sprintf(format, args...))
|
|
|
|
}
|
|
|
|
|
2020-12-25 11:14:01 +00:00
|
|
|
func Wrap(err error, msg string) error {
|
|
|
|
if err == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return fmt.Errorf("%s: %w", msg, err)
|
|
|
|
}
|
2021-01-05 19:50:39 +00:00
|
|
|
|
|
|
|
func New(text string) error {
|
|
|
|
return errors.New(text)
|
|
|
|
}
|