Debian Codegraph @

encoding/errors.go

raw symbols SCIP
1 package encoding
2
3 import (
4 "fmt"
5 "reflect"
6 "strings"
7 )
8
9 type MarshalerError struct {
10 Type reflect.Type
11 Err error
12 }
13
14 func (e *MarshalerError) Error() string {
15 return "rethinkdb: error calling MarshalRQL for type " + e.Type.String() + ": " + e.Err.Error()
16 }
17
18 type InvalidUnmarshalError struct {
19 Type reflect.Type
20 }
21
22 func (e *InvalidUnmarshalError) Error() string {
23 if e.Type == nil {
24 return "rethinkdb: UnmarshalRQL(nil)"
25 }
26
27 if e.Type.Kind() != reflect.Ptr {
28 return "rethinkdb: UnmarshalRQL(non-pointer " + e.Type.String() + ")"
29 }
30 return "rethinkdb: UnmarshalRQL(nil " + e.Type.String() + ")"
31 }
32
33 // An InvalidTypeError describes a value that was
34 // not appropriate for a value of a specific Go type.
35 type DecodeTypeError struct {
36 DestType, SrcType reflect.Type
37 Reason string
38 }
39
40 func (e *DecodeTypeError) Error() string {
41 if e.Reason != "" {
42 return "rethinkdb: could not decode type " + e.SrcType.String() + " into Go value of type " + e.DestType.String() + ": " + e.Reason
43 } else {
44 return "rethinkdb: could not decode type " + e.SrcType.String() + " into Go value of type " + e.DestType.String()
45 }
46 }
47
48 // An UnsupportedTypeError is returned by Marshal when attempting
49 // to encode an unsupported value type.
50 type UnsupportedTypeError struct {
51 Type reflect.Type
52 }
53
54 func (e *UnsupportedTypeError) Error() string {
55 return "rethinkdb: unsupported type: " + e.Type.String()
56 }
57
58 // An UnsupportedTypeError is returned by Marshal when attempting
59 // to encode an unexpected value type.
60 type UnexpectedTypeError struct {
61 DestType, SrcType reflect.Type
62 }
63
64 func (e *UnexpectedTypeError) Error() string {
65 return "rethinkdb: expected type: " + e.DestType.String() + ", got " + e.SrcType.String()
66 }
67
68 type UnsupportedValueError struct {
69 Value reflect.Value
70 Str string
71 }
72
73 func (e *UnsupportedValueError) Error() string {
74 return "rethinkdb: unsupported value: " + e.Str
75 }
76
77 // Error implements the error interface and can represents multiple
78 // errors that occur in the course of a single decode.
79 type Error struct {
80 Errors []string
81 }
82
83 func (e *Error) Error() string {
84 points := make([]string, len(e.Errors))
85 for i, err := range e.Errors {
86 points[i] = fmt.Sprintf("* %s", err)
87 }
88
89 return fmt.Sprintf(
90 "%d error(s) decoding:\n\n%s",
91 len(e.Errors), strings.Join(points, "\n"))
92 }
93
94 func appendErrors(errors []string, err error) []string {
95 switch e := err.(type) {
96 case *Error:
97 return append(errors, e.Errors...)
98 default:
99 return append(errors, e.Error())
100 }
101 }