zk/internal/util/errors/errors.go

36 lines
641 B
Go
Raw Normal View History

package errors
import (
2021-01-05 19:50:39 +00:00
"errors"
"fmt"
)
2020-12-26 15:53:04 +00:00
func Wrapperf(format string, args ...interface{}) func(error) error {
return Wrapper(fmt.Sprintf(format, args...))
}
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...))
}
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)
}
func As(err error, target interface{}) bool {
return errors.As(err, target)
}