forked from rethinkdb/rethinkdb-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
102 lines (83 loc) · 2.44 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
100
101
102
package encoding
import (
"fmt"
"reflect"
"strings"
)
type MarshalerError struct {
Type reflect.Type
Err error
}
func (e *MarshalerError) Error() string {
return "gorethink: error calling MarshalRQL for type " + e.Type.String() + ": " + e.Err.Error()
}
type InvalidUnmarshalError struct {
Type reflect.Type
}
func (e *InvalidUnmarshalError) Error() string {
if e.Type == nil {
return "gorethink: UnmarshalRQL(nil)"
}
if e.Type.Kind() != reflect.Ptr {
return "gorethink: UnmarshalRQL(non-pointer " + e.Type.String() + ")"
}
return "gorethink: UnmarshalRQL(nil " + e.Type.String() + ")"
}
// An InvalidTypeError describes a value that was
// not appropriate for a value of a specific Go type.
type DecodeTypeError struct {
DestType, SrcType reflect.Type
Reason string
}
func (e *DecodeTypeError) Error() string {
if e.Reason != "" {
return "gorethink: could not decode type " + e.SrcType.String() + " into Go value of type " + e.DestType.String() + ": " + e.Reason
} else {
return "gorethink: could not decode type " + e.SrcType.String() + " into Go value of type " + e.DestType.String()
}
}
// An UnsupportedTypeError is returned by Marshal when attempting
// to encode an unsupported value type.
type UnsupportedTypeError struct {
Type reflect.Type
}
func (e *UnsupportedTypeError) Error() string {
return "gorethink: unsupported type: " + e.Type.String()
}
// An UnsupportedTypeError is returned by Marshal when attempting
// to encode an unexpected value type.
type UnexpectedTypeError struct {
DestType, SrcType reflect.Type
}
func (e *UnexpectedTypeError) Error() string {
return "gorethink: expected type: " + e.DestType.String() + ", got " + e.SrcType.String()
}
type UnsupportedValueError struct {
Value reflect.Value
Str string
}
func (e *UnsupportedValueError) Error() string {
return "gorethink: unsupported value: " + e.Str
}
// Error implements the error interface and can represents multiple
// errors that occur in the course of a single decode.
type Error struct {
Errors []string
}
func (e *Error) Error() string {
points := make([]string, len(e.Errors))
for i, err := range e.Errors {
points[i] = fmt.Sprintf("* %s", err)
}
return fmt.Sprintf(
"%d error(s) decoding:\n\n%s",
len(e.Errors), strings.Join(points, "\n"))
}
func appendErrors(errors []string, err error) []string {
switch e := err.(type) {
case *Error:
return append(errors, e.Errors...)
default:
return append(errors, e.Error())
}
}