/
err.go
155 lines (128 loc) · 4.76 KB
/
err.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package nbt
import (
"fmt"
"reflect"
)
// InvalidTypeError is returned when the type of a tag read is not equal to the struct field with the name
// of that tag.
type InvalidTypeError struct {
Off int64
Field string
TagType byte
FieldType reflect.Type
}
// Error ...
func (err InvalidTypeError) Error() string {
return fmt.Sprintf("nbt: invalid type for tag '%v' at offset %v: cannot unmarshalTag %v into %v", err.Field, err.Off, tagName(err.TagType), err.FieldType)
}
// UnknownTagError is returned when the type of a tag read is not known, meaning it is not found in the tag.go
// file.
type UnknownTagError struct {
Off int64
Op string
TagType byte
}
// Error ...
func (err UnknownTagError) Error() string {
return fmt.Sprintf("nbt: unknown tag '%v' at offset %v during op '%v'", err.TagType, err.Off, err.Op)
}
// UnexpectedTagError is returned when a tag type encountered was not expected, and thus valid in its context.
type UnexpectedTagError struct {
Off int64
TagType byte
}
// Error ...
func (err UnexpectedTagError) Error() string {
return fmt.Sprintf("nbt: unexpected tag %v at offset %v: tag is not valid in its context", tagName(err.TagType), err.Off)
}
// NonPointerTypeError is returned when the type of a value passed in Decoder.Decode or Unmarshal is not a
// pointer.
type NonPointerTypeError struct {
ActualType reflect.Type
}
// Error ...
func (err NonPointerTypeError) Error() string {
return fmt.Sprintf("nbt: expected ptr type to decode into, but got '%v'", err.ActualType)
}
// BufferOverrunError is returned when the data buffer passed in when reading is overrun, meaning one of the
// reading operations extended beyond the end of the slice.
type BufferOverrunError struct {
Op string
}
// Error ...
func (err BufferOverrunError) Error() string {
return fmt.Sprintf("nbt: unexpected buffer end during op: '%v'", err.Op)
}
// InvalidArraySizeError is returned when an array read from the NBT (that includes byte arrays, int32 arrays
// and int64 arrays) does not have the same size as the Go representation.
type InvalidArraySizeError struct {
Off int64
Op string
GoLength int
NBTLength int
}
// Error ...
func (err InvalidArraySizeError) Error() string {
return fmt.Sprintf("nbt: mismatched array size at %v during op '%v': expected size %v, found %v in NBT", err.Off, err.Op, err.GoLength, err.NBTLength)
}
// UnexpectedNamedTagError is returned when a named tag is read from a compound which is not present in the
// struct it is decoded into.
type UnexpectedNamedTagError struct {
Off int64
TagName string
TagType byte
}
// Error ...
func (err UnexpectedNamedTagError) Error() string {
return fmt.Sprintf("nbt: unexpected named tag '%v' with type %v at offset %v: not present in struct to be decoded into", err.TagName, tagName(err.TagType), err.Off)
}
// FailedWriteError is returned if a Write operation failed on an offsetWriter, meaning some of the data could
// not be written to the io.Writer.
type FailedWriteError struct {
Off int64
Op string
Err error
}
// Error ...
func (err FailedWriteError) Error() string {
return fmt.Sprintf("nbt: failed write during op '%v' at offset %v: %v", err.Op, err.Off, err.Err)
}
// IncompatibleTypeError is returned if a value is attempted to be written to an io.Writer, but its type can-
// not be translated to an NBT tag.
type IncompatibleTypeError struct {
ValueName string
Type reflect.Type
}
// Error ...
func (err IncompatibleTypeError) Error() string {
return fmt.Sprintf("nbt: value type %v (%v) cannot be translated to an NBT tag", err.Type, err.ValueName)
}
// InvalidStringError is returned if a string read is not valid, meaning it does not exist exclusively out of
// utf8 characters, or if it is longer than the length prefix can carry.
type InvalidStringError struct {
Off int64
Err error
String string
}
// Error ...
func (err InvalidStringError) Error() string {
return fmt.Sprintf("nbt: string at offset %v is not valid: %v (%v)", err.Off, err.Err, err.String)
}
const maximumNestingDepth = 512
// MaximumDepthReachedError is returned if the maximum depth of 512 compound/list tags has been reached while
// reading or writing NBT.
type MaximumDepthReachedError struct {
}
// Error ...
func (err MaximumDepthReachedError) Error() string {
return fmt.Sprintf("nbt: maximum nesting depth of %v was reached", maximumNestingDepth)
}
const maximumNetworkOffset = 4 * 1024 * 1024
// MaximumBytesReadError is returned if the maximum amount of bytes has been read for NetworkLittleEndian
// format. It is returned if the offset hits maximumNetworkOffset.
type MaximumBytesReadError struct {
}
// Error ...
func (err MaximumBytesReadError) Error() string {
return fmt.Sprintf("nbt: limit of bytes read %v with NetworkLittleEndian format exhausted", maximumNetworkOffset)
}