forked from pkg/errors
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase.go
47 lines (39 loc) · 857 Bytes
/
base.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
42
43
44
45
46
47
package errors
import (
"fmt"
"reflect"
)
func formatterPlusV(s fmt.State, verb rune, err error) {
if f, ok := err.(fmt.Formatter); ok {
f.Format(s, verb)
} else {
fmt.Fprintf(s, "%+v", err)
}
}
type unwrapper interface {
Unwrap() error
}
type unwraps interface {
Unwrap() []error
}
type errorUnwrap interface {
Unwrap() error
// ErrorNoUnwrap is the error message component of the wrapping
// It will be a prefix of Error()
// If there is no message in the wrapping then this can return an empty string
ErrorNoUnwrap() string
}
func isNil(err error) bool {
if err == nil {
return true
}
v := reflect.ValueOf(err)
k := v.Kind()
switch k {
case reflect.Pointer, reflect.UnsafePointer, reflect.Interface:
return v.IsNil()
case reflect.Slice, reflect.Array, reflect.Map:
return v.IsNil() || v.Len() == 0
}
return false
}