-
Notifications
You must be signed in to change notification settings - Fork 2
/
error.go
76 lines (67 loc) · 1.89 KB
/
error.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package mapper
import (
"fmt"
"reflect"
"strings"
)
/***************************
@author: tiansheng.ren
@date: 2022/10/24
@desc:
***************************/
// CopyValueError copy element does not match destination element
type CopyValueError struct {
Name string
Types []reflect.Type
Kinds []reflect.Kind
Received reflect.Value
}
func (vde CopyValueError) Error() string {
typeKinds := make([]string, 0, len(vde.Types)+len(vde.Kinds))
for _, t := range vde.Types {
typeKinds = append(typeKinds, t.String())
}
for _, k := range vde.Kinds {
if k == reflect.Map {
typeKinds = append(typeKinds, "map[*]*")
continue
}
typeKinds = append(typeKinds, k.String())
}
received := vde.Received.Kind().String()
if vde.Received.IsValid() {
received = vde.Received.Type().String()
}
return fmt.Sprintf("%s can only copy valid and settable %s, but got %s", vde.Name, strings.Join(typeKinds, ", "), received)
}
type CanSetError struct {
Name string
}
func (cse CanSetError) Error() string {
return fmt.Sprintf("%s copy to object must be pointers", cse.Name)
}
// LookupCopyValueError The current received element does not match the function
type LookupCopyValueError struct {
Name string
Types []reflect.Type
Kinds []reflect.Kind
Received reflect.Value
}
func (l LookupCopyValueError) Error() string {
typeKinds := make([]string, 0, len(l.Types)+len(l.Kinds))
for _, t := range l.Types {
typeKinds = append(typeKinds, t.String())
}
for _, k := range l.Kinds {
if k == reflect.Map {
typeKinds = append(typeKinds, "map[*]*")
continue
}
typeKinds = append(typeKinds, k.String())
}
received := l.Received.Kind().String()
if l.Received.IsValid() {
received = l.Received.Type().String()
}
return fmt.Sprintf("%s lookup copy function error, function can only copy valid and settable %s, but got %s", l.Name, strings.Join(typeKinds, ", "), received)
}