-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy patherrors.go
More file actions
executable file
·100 lines (87 loc) · 3.09 KB
/
Copy patherrors.go
File metadata and controls
executable file
·100 lines (87 loc) · 3.09 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
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
package bertlv
import (
"fmt"
"reflect"
)
// DecodeError represents an error that occurred during BER-TLV decoding.
type DecodeError struct {
Offset int
Field string
Type reflect.Type
Message string
}
// Error implements the error interface for DecodeError.
func (e *DecodeError) Error() string {
if e.Field != "" {
return fmt.Sprintf("bertlv: offset %d: cannot decode into field %s (type %s): %s",
e.Offset, e.Field, e.Type, e.Message)
}
return fmt.Sprintf("bertlv: offset %d: %s", e.Offset, e.Message)
}
// EncodeError represents an error that occurred during BER-TLV encoding.
type EncodeError struct {
Type reflect.Type
Field string
Message string
}
// Error implements the error interface for EncodeError.
func (e *EncodeError) Error() string {
if e.Field != "" {
return fmt.Sprintf("bertlv: cannot encode field %s (type %s): %s",
e.Field, e.Type, e.Message)
}
if e.Type != nil {
return fmt.Sprintf("bertlv: cannot encode type %s: %s", e.Type, e.Message)
}
return fmt.Sprintf("bertlv: encode error: %s", e.Message)
}
// UnmarshalTypeError describes a BER-TLV value that was
// not appropriate for a value of a specific Go type.
type UnmarshalTypeError struct {
Value string // description of BER-TLV value
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
}
// Error implements the error interface for UnmarshalTypeError.
func (e *UnmarshalTypeError) Error() string {
if e.Struct != "" || e.Field != "" {
return fmt.Sprintf("bertlv: cannot unmarshal %s into Go struct field %s.%s of type %s",
e.Value, e.Struct, e.Field, e.Type.String())
}
return fmt.Sprintf("bertlv: cannot unmarshal %s into Go value of type %s",
e.Value, e.Type.String())
}
// InvalidUnmarshalError describes an invalid argument passed to Unmarshal.
type InvalidUnmarshalError struct {
Type reflect.Type
}
// Error implements the error interface for InvalidUnmarshalError.
func (e *InvalidUnmarshalError) Error() string {
if e.Type == nil {
return "bertlv: Unmarshal(nil)"
}
if e.Type.Kind() != reflect.Pointer {
return "bertlv: Unmarshal(non-pointer " + e.Type.String() + ")"
}
return "bertlv: Unmarshal(nil " + e.Type.String() + ")"
}
// MissingRequiredFieldError describes that field that was marked as required wasn't encountered in the BER-TLV data.
type MissingRequiredFieldError struct {
Field string
Tag TagInfo
}
// Error implements the error interface for MissingRequiredFieldError.
func (e *MissingRequiredFieldError) Error() string {
return fmt.Sprintf("bertlv: missing required tag %s for field '%s'", e.Tag, e.Field)
}
// UnknownFieldError is returned when an unknown tag is encountered with DisallowUnknownFields.
type UnknownFieldError struct {
Tag TagInfo
Offset int
}
// Error implements the error interface for UnknownFieldError.
func (e *UnknownFieldError) Error() string {
return fmt.Sprintf("bertlv: unknown tag %s at offset %d", e.Tag.String(), e.Offset)
}