Skip to content

Commit c393741

Browse files
Alex SchAlex Sch
authored andcommitted
make it compatible with native 'errors' package
1 parent 26856b9 commit c393741

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

native.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package errors
2+
3+
import "errors"
4+
5+
// New returns an error that formats as the given text.
6+
// Wraps original errors.New function to avoid importing "errors".
7+
func New(text string) error {
8+
return errors.New(text)
9+
}
10+
11+
// Is reports whether any error in err's chain matches target.
12+
// Wraps original errors.Is function to avoid importing "errors".
13+
func Is(err, target error) bool {
14+
return errors.Is(err, target)
15+
}
16+
17+
// As finds the first error in err's chain that matches target, and if one is found,
18+
// sets target to that error value and returns true. Otherwise, it returns false.
19+
// Wraps original errors.As function to avoid importing "errors".
20+
func As(err error, target interface{}) bool {
21+
return errors.As(err, target)
22+
}
23+
24+
// Unwrap returns the result of calling the Unwrap method on err, if err's type contains
25+
// an Unwrap method returning error. Otherwise, Unwrap returns nil.
26+
// Wraps original errors.Unwrap function to avoid importing "errors".
27+
func Unwrap(err error) error {
28+
return errors.Unwrap(err)
29+
}

0 commit comments

Comments
 (0)