-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy patherror.go
103 lines (82 loc) · 2.69 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package csvutil
import (
"errors"
"reflect"
)
// ErrFieldCount is returned when header's length doesn't match the length of
// the read record.
var ErrFieldCount = errors.New("wrong number of fields in record")
// An UnmarshalTypeError describes a string value that was not appropriate for
// a value of a specific Go type.
type UnmarshalTypeError struct {
Value string // string value
Type reflect.Type // type of Go value it could not be assigned to
}
func (e *UnmarshalTypeError) Error() string {
return "csvutil: cannot unmarshal " + e.Value + " into Go value of type " + e.Type.String()
}
// An UnsupportedTypeError is returned when attempting to decode an unsupported
// value type.
type UnsupportedTypeError struct {
Type reflect.Type
}
func (e *UnsupportedTypeError) Error() string {
return "csvutil: unsupported type: " + e.Type.String()
}
// An InvalidDecodeError describes an invalid argument passed to Decode.
// (The argument to Decode must be a non-nil pointer.)
type InvalidDecodeError struct {
Type reflect.Type
}
func (e *InvalidDecodeError) Error() string {
if e.Type == nil {
return "csvutil: Decode(nil)"
}
if e.Type.Kind() != reflect.Ptr {
return "csvutil: Decode(non-pointer " + e.Type.String() + ")"
}
if indirect(reflect.New(e.Type)).Type().Kind() != reflect.Struct {
return "csvutil: Decode(non-struct pointer)"
}
return "csvutil: Decode(nil " + e.Type.String() + ")"
}
// An InvalidUnmarshalError describes an invalid argument passed to Unmarshal.
// (The argument to Unmarshal must be a non-nil slice pointer.)
type InvalidUnmarshalError struct {
Type reflect.Type
}
func (e *InvalidUnmarshalError) Error() string {
if e.Type == nil {
return "csvutil: Unmarshal(nil)"
}
if e.Type.Kind() != reflect.Ptr {
return "csvutil: Unmarshal(non-pointer " + e.Type.String() + ")"
}
return "csvutil: Unmarshal(non-slice pointer)"
}
// InvalidEncodeError is returned by Encode when the passed argument v is not
// a struct.
type InvalidEncodeError struct {
Type reflect.Type
}
func (e *InvalidEncodeError) Error() string {
return "csvutil: Encode(" + e.Type.String() + ")"
}
// InvalidMarshalError is returned by Marshal when the provided type was
// not a slice.
type InvalidMarshalError struct {
Type reflect.Type
}
func (e *InvalidMarshalError) Error() string {
return "csvutil: Marshal(non-slice " + e.Type.String() + ")"
}
// MarshalerError is returned by Encoder when MarshalCSV or MarshalText returned
// an error.
type MarshalerError struct {
Type reflect.Type
MarshalerType string
Err error
}
func (e *MarshalerError) Error() string {
return "csvutil: error calling " + e.MarshalerType + " for type " + e.Type.String() + ": " + e.Err.Error()
}