-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patherrors_decoder.go
133 lines (104 loc) · 3.54 KB
/
errors_decoder.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package jzon
import (
"errors"
"fmt"
)
// DecodeError describes the encountered error and its location.
type DecodeError struct {
reason error
location string
}
func (e *DecodeError) Error() string {
return fmt.Sprintf("%s (near %s)", e.reason.Error(), e.location)
}
// ErrDataRemained there is still data remained in the buffer
// normally returned by Unmarshal methods
var ErrDataRemained = errors.New("expecting EOF, but there is still data")
// ErrPointerReceiver if the decode target is not a pointer
var ErrPointerReceiver = errors.New("the receiver is not a pointer")
// ErrNilPointerReceiver if the decode target is nil
var ErrNilPointerReceiver = errors.New("the receiver is nil")
// ErrEmptyIFace if the decode target is an empty interface (with method)
var ErrEmptyIFace = errors.New("cannot unmarshal on empty iface")
// ErrNilEmbeddedPointer if the decode target has an unexported nil field
var ErrNilEmbeddedPointer = errors.New("cannot unmarshal on nil pointer (unexported embedded)")
// ErrEfaceLooping if we encountered a loop
// for example:
// type iface interface{}
// var o1 iface
// o1 = &o1
// err := DefaultDecoderConfig.Unmarshal([]byte(`1`), o1)
var ErrEfaceLooping = errors.New("eface looping detected")
// InvalidStringCharError there is an invalid character when reading string
type InvalidStringCharError struct {
c byte
}
func (e InvalidStringCharError) Error() string {
return fmt.Sprintf("invalid character %x found", e.c)
}
// InvalidEscapeCharError there is an invalid escape character (when reading string)
type InvalidEscapeCharError struct {
c byte
}
func (e InvalidEscapeCharError) Error() string {
return fmt.Sprintf("invalid escape character \\%x found", e.c)
}
// InvalidUnicodeCharError there is an invalid unicode character (when reading string)
type InvalidUnicodeCharError struct {
c byte
}
func (e InvalidUnicodeCharError) Error() string {
return fmt.Sprintf("invalid unicode character %x found", e.c)
}
// UnexpectedByteError there is an unexpected character
type UnexpectedByteError struct {
got byte
exp byte
exp2 byte
}
func (e UnexpectedByteError) Error() string {
if e.exp == 0 {
return fmt.Sprintf("unexpected character %q", e.got)
}
if e.exp2 == 0 {
return fmt.Sprintf("expecting %q but got %q", e.exp, e.got)
}
return fmt.Sprintf("expecting %q or %q but got %q", e.exp, e.exp2, e.got)
}
// IntOverflowError the integer overflows.
type IntOverflowError struct {
typ string
value string
}
func (e IntOverflowError) Error() string {
return fmt.Sprintf("overflow %s: %s", e.typ, e.value)
}
// InvalidDigitError there is an invalid digit when reading number
type InvalidDigitError struct {
c byte
}
func (e InvalidDigitError) Error() string {
return fmt.Sprintf("invalid digit character: %q", e.c)
}
// InvalidFloatError there is an invalid digit when reading float
type InvalidFloatError struct {
c byte
}
func (e InvalidFloatError) Error() string {
return fmt.Sprintf("invalid float character: %q", e.c)
}
// TypeNotSupportedError the decode target is not supported
type TypeNotSupportedError string
func (e TypeNotSupportedError) Error() string {
return fmt.Sprintf("%q is not supported", string(e))
}
// UnknownFieldError there is an unknown field when decoding
type UnknownFieldError string
func (e UnknownFieldError) Error() string {
return fmt.Sprintf("unknown field %q", string(e))
}
// BadQuotedStringError the value of field is not correctly quoted
type BadQuotedStringError string
func (e BadQuotedStringError) Error() string {
return fmt.Sprintf("bad quoted string %q", string(e))
}