-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
41 lines (34 loc) · 1010 Bytes
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package errors
import (
"errors"
"fmt"
)
// As calls errors.As from the standard library.
func As(err error, target interface{}) bool {
return errors.As(err, target)
}
// Is calls errors.Is from the standard library.
func Is(err, target error) bool {
return errors.Is(err, target)
}
// New calls errors.New from the standard library.
func New(text string) error {
return errors.New(text)
}
// Unwrap calls errors.Unwrap from the standard library.
func Unwrap(err error) error {
return errors.Unwrap(err)
}
// Wrap returns the provided error annotated with the supplied message using
// fmt.Errorf. If err is nil, Wrap returns nil.
func Wrap(err error, message string) error {
if err == nil {
return nil
}
return fmt.Errorf("%v: %w", message, err)
}
// Wrapf returns the provided error annotated with the supplied message using
// fmt.Errorf. If err is nil, Wrapf returns nil.
func Wrapf(err error, format string, args ...interface{}) error {
return Wrap(err, fmt.Sprintf(format, args...))
}