-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.go
63 lines (53 loc) · 1.92 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
package packet
import (
"reflect"
)
// UnmarshalPtrError error from expected pointer not found
type UnmarshalPtrError struct {
Type reflect.Type
}
func (e *UnmarshalPtrError) Error() string {
if e.Type == nil {
return "packet: Unmarshal(nil)"
}
if e.Type.Kind() != reflect.Ptr {
return "packet: Unmarshal(non-pointer " + e.Type.String() + ")"
}
return "packet: Unmarshal(nil " + e.Type.String() + ")"
}
// An UnmarshalTypeError describes a packet value that was
// not appropriate for a value of a specific Go type.
type UnmarshalTypeError struct {
Value string // description of packet value - "bool", "array", "number -5"
Type reflect.Type // type of Go value it could not be assigned to
Offset int64 // error occurred after reading Offset bytes
Struct string // name of the struct type containing the field
Field string // name of the field holding the Go value
}
func (e *UnmarshalTypeError) Error() string {
if e.Struct != "" || e.Field != "" {
return "packet: cannot unmarshal " + e.Value + " into Go struct field " + e.Struct + "." + e.Field + " of type " + e.Type.String()
}
return "packet: cannot unmarshal " + e.Value + " into Go value of type " + e.Type.String()
}
// An UnmarshalBitfieldOverflowError describes a condition where bit reading overflows uint64 holder
type UnmarshalBitfieldOverflowError struct {
Struct string
Field reflect.StructField
}
func (e *UnmarshalBitfieldOverflowError) Error() string {
if e.Struct != "" {
return "packet: cannot unmarshal " + e.Field.Name + " into Go struct field " + e.Struct + ", size over 64bits"
}
return "packet: cannot unmarshal into Go value of type " + e.Struct
}
// UnmarshalUnexpectedEnd unexpected end of data
type UnmarshalUnexpectedEnd struct {
Struct string
Field string
Offset int64
End int64
}
func (e *UnmarshalUnexpectedEnd) Error() string {
return "packet: premature end of data for " + e.Struct + "." + e.Field
}