-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.go
99 lines (77 loc) · 1.93 KB
/
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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package dynstruct
import (
"fmt"
"reflect"
)
type unmatchedTypeError struct {
t string
field string
expected string
got string
}
func makeUnmatchedTypeError(t *DynStruct, field string, expected, got reflect.Type) error {
return unmatchedTypeError{
t: t.String(),
field: field,
expected: expected.String(),
got: got.String(),
}
}
func (e unmatchedTypeError) Error() string {
return fmt.Sprintf("field %#v of type %#v unmatched type: expected %#v, got %#v", e.field, e.t, e.expected, e.got)
}
type missingFieldError struct {
t string
field string
}
func makeMissingFieldError(t *DynStruct, field string) error {
return missingFieldError{t: t.String(), field: field}
}
func (e missingFieldError) Error() string {
return fmt.Sprintf("type %#v missing field %#v", e.t, e.field)
}
type unknownTypeError struct{}
func makeUnknownTypeError() error {
return unknownTypeError{}
}
func (e unknownTypeError) Error() string {
return "unknown type"
}
type invalidNameError struct {
t string
name string
}
func makeInvalidNameError(t, name string) error {
return invalidNameError{t: t, name: name}
}
func (e invalidNameError) Error() string {
return fmt.Sprintf("invalid %s name: %#v", e.t, e.name)
}
type recallError struct {
f string
}
func makeRecallError(f string) error {
return recallError{f: f}
}
func (e recallError) Error() string {
return fmt.Sprintf("call function %#v more than once", e.f)
}
type repeatedNameError struct {
t string
name string
}
func makeRepeatedNameError(t, name string) error {
return repeatedNameError{t: t, name: name}
}
func (e repeatedNameError) Error() string {
return fmt.Sprintf("repeated %s name: %#v", e.t, e.name)
}
type nilFieldTypeError struct {
field string
}
func makeNilTypeError(field string) error {
return nilFieldTypeError{field: field}
}
func (e nilFieldTypeError) Error() string {
return fmt.Sprintf("type of field %#v is nil", e.field)
}