-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
57 lines (47 loc) · 1.31 KB
/
Copy patherrors.go
File metadata and controls
57 lines (47 loc) · 1.31 KB
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
package jsonx
import (
"fmt"
"reflect"
)
type SyntaxError struct {
Msg string
Offset int64
}
func (e *SyntaxError) Error() string {
return fmt.Sprintf("jsonx: %s at offset %d", e.Msg, e.Offset)
}
type UnmarshalTypeError struct {
Value string
Type reflect.Type
Offset int64
Struct string // name of the outermost struct containing the field, if any
Field string // dotted path of the field within that struct, if any
}
func (e *UnmarshalTypeError) Error() string {
if e.Struct != "" || e.Field != "" {
return fmt.Sprintf("jsonx: cannot unmarshal %s into Go struct field %s.%s of type %s",
e.Value, e.Struct, e.Field, e.Type)
}
return fmt.Sprintf("jsonx: cannot unmarshal %s into Go value of type %s", e.Value, e.Type)
}
type InvalidUnmarshalError struct {
Type reflect.Type
}
func (e *InvalidUnmarshalError) Error() string {
if e.Type == nil {
return "jsonx: Unmarshal(nil)"
}
if e.Type.Kind() != reflect.Ptr {
return fmt.Sprintf("jsonx: Unmarshal(non-pointer %s)", e.Type)
}
return fmt.Sprintf("jsonx: Unmarshal(nil %s)", e.Type)
}
type UnsupportedTypeError struct {
Type reflect.Type
}
func (e *UnsupportedTypeError) Error() string {
return fmt.Sprintf("jsonx: unsupported type: %s", e.Type)
}
func syntaxErr(msg string, off int) error {
return &SyntaxError{Msg: msg, Offset: int64(off)}
}