...
1 package document
2
3 import (
4 "fmt"
5 "reflect"
6 )
7
8
9
10
11 type UnmarshalTypeError struct {
12 Value string
13 Type reflect.Type
14 }
15
16
17
18 func (e *UnmarshalTypeError) Error() string {
19 return fmt.Sprintf("unmarshal failed, cannot unmarshal %s into Go value type %s",
20 e.Value, e.Type.String())
21 }
22
23
24
25 type InvalidUnmarshalError struct {
26 Type reflect.Type
27 }
28
29
30
31 func (e *InvalidUnmarshalError) Error() string {
32 var msg string
33 if e.Type == nil {
34 msg = "cannot unmarshal to nil value"
35 } else if e.Type.Kind() != reflect.Ptr {
36 msg = fmt.Sprintf("cannot unmarshal to non-pointer value, got %s", e.Type.String())
37 } else {
38 msg = fmt.Sprintf("cannot unmarshal to nil value, %s", e.Type.String())
39 }
40
41 return fmt.Sprintf("unmarshal failed, %s", msg)
42 }
43
44
45
46
47 type UnmarshalError struct {
48 Err error
49 Value string
50 Type reflect.Type
51 }
52
53
54 func (e *UnmarshalError) Unwrap() error {
55 return e.Err
56 }
57
58
59
60 func (e *UnmarshalError) Error() string {
61 return fmt.Sprintf("unmarshal failed, cannot unmarshal %q into %s, %v",
62 e.Value, e.Type.String(), e.Err)
63 }
64
65
66
67 type InvalidMarshalError struct {
68 Message string
69 }
70
71
72
73 func (e *InvalidMarshalError) Error() string {
74 return fmt.Sprintf("marshal failed, %s", e.Message)
75 }
76
View as plain text