-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
errors.go
39 lines (32 loc) · 787 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
package retry
const internal Error = "have no any try"
// Error defines a string-based error without a different root cause.
type Error string
// Error returns a string representation of an error.
func (err Error) Error() string { return string(err) }
// Unwrap always returns nil means that an error doesn't have other root cause.
func (err Error) Unwrap() error { return nil }
func unwrap(err error) error {
for err != nil {
layer, is := err.(wrapper)
if is {
err = layer.Unwrap()
continue
}
cause, is := err.(causer)
if is {
err = cause.Cause()
continue
}
break
}
return err
}
// compatible with github.com/pkg/errors
type causer interface {
Cause() error
}
// compatible with built-in errors since 1.13
type wrapper interface {
Unwrap() error
}