-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
348 lines (268 loc) · 9.64 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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
package acmelib
import (
"errors"
"fmt"
)
// ErrIsDuplicated is returned when an entity is duplicated.
var ErrIsDuplicated = errors.New("is duplicated")
// ErrNotFound is returned when an entity is not found.
var ErrNotFound = errors.New("not found")
// ErrIsNegative is returned when a value is negative.
var ErrIsNegative = errors.New("is negative")
// ErrOutOfBounds is returned when a value is out of bounds.
var ErrOutOfBounds = errors.New("out of bounds")
// ErrIsZero is returned when a value is zero.
var ErrIsZero = errors.New("is zero")
// ErrIsNil is returned when a value or entity is nil.
var ErrIsNil = errors.New("is nil")
// ErrNoSpaceLeft is returned when there is not enough space left.
var ErrNoSpaceLeft = errors.New("not enough space left")
// ErrIntersect is returned when two entities are intersecting.
var ErrIntersect = errors.New("is intersecting")
// ErrInvalidType is returned when an invalid type is used.
var ErrInvalidType = errors.New("invalid type")
// ErrReceiverIsSender is returned when the receiver is the sender.
var ErrReceiverIsSender = errors.New("receiver is sender")
// ErrInvalidOneof is returned when a oneof field does not match
// a kind/type field.
type ErrInvalidOneof struct {
KindTypeField string
}
func (e *ErrInvalidOneof) Error() string {
return fmt.Sprintf("kind/type field must be %q for this oneof field", e.KindTypeField)
}
// ErrMissingOneofField is returned when a oneof field is missing.
type ErrMissingOneofField struct {
OneofField string
}
func (e *ErrMissingOneofField) Error() string {
return fmt.Sprintf("oneof field %q is missing", e.OneofField)
}
// ErrIsRequired is returned when something is required.
// The Thing field is what is required.
type ErrIsRequired struct {
Item string
}
func (e *ErrIsRequired) Error() string {
return fmt.Sprintf("%q is required", e.Item)
}
// ErrGreaterThen is returned when a value is greater than a target.
// The Target field is the target.
type ErrGreaterThen struct {
Target string
}
func (e *ErrGreaterThen) Error() string {
return fmt.Sprintf("is greater then %q", e.Target)
}
// ErrLowerThen is returned when a value is lower than a target.
// The Target field is the target.
type ErrLowerThen struct {
Target string
}
func (e *ErrLowerThen) Error() string {
return fmt.Sprintf("is lower then %q", e.Target)
}
// EntityError is returned when a method of an entity fails.
// The Kind field is the entity kind, the EntityID field is the ID,
// the Name field is the name, and the Err field is the cause.
type EntityError struct {
Kind EntityKind
EntityID EntityID
Name string
Err error
}
func (e *EntityError) Error() string {
return fmt.Sprintf("%s error; entity_id:%q, name:%q : %v", e.Kind, e.EntityID.String(), e.Name, e.Err)
}
func (e *EntityError) Unwrap() error { return e.Err }
// GetEntityError is returned when an entity cannot be retrieved.
// The EntityID field is the ID of the entity and the Err field is the cause.
type GetEntityError struct {
EntityID EntityID
Err error
}
func (e *GetEntityError) Error() string {
return fmt.Sprintf("get entity error; entity_id:%q : %v", e.EntityID, e.Err)
}
func (e *GetEntityError) Unwrap() error { return e.Err }
// AddEntityError is returned when an entity cannot be added.
// The EntityID field is the ID of the entity and the Name field is the name,
// and the Err field is the cause.
type AddEntityError struct {
EntityID EntityID
Name string
Err error
}
func (e *AddEntityError) Error() string {
return fmt.Sprintf("add entity error; entity_id:%q, name:%q : %v", e.EntityID.String(), e.Name, e.Err)
}
func (e *AddEntityError) Unwrap() error { return e.Err }
// RemoveEntityError is returned when an entity cannot be removed.
// The EntityID field is the ID of the entity and the Err field is the cause.
type RemoveEntityError struct {
EntityID EntityID
Err error
}
func (e *RemoveEntityError) Error() string {
return fmt.Sprintf("remove entity error; entity_id:%q : %v", e.EntityID.String(), e.Err)
}
func (e *RemoveEntityError) Unwrap() error { return e.Err }
// ArgumentError is returned when an argument is invalid.
// The Name field is the name of the argument and the Err field is the cause.
type ArgumentError struct {
Name string
Err error
}
func (e *ArgumentError) Error() string {
return fmt.Sprintf("argument error; name:%q : %v", e.Name, e.Err)
}
func (e *ArgumentError) Unwrap() error { return e.Err }
// NameError is returned when a name is invalid.
// The Name field is the name and the Err field is the cause.
type NameError struct {
Name string
Err error
}
func (e *NameError) Error() string {
return fmt.Sprintf("name error; name:%q : %v", e.Name, e.Err)
}
func (e *NameError) Unwrap() error { return e.Err }
// UpdateNameError is returned when a name cannot be updated.
type UpdateNameError struct {
Err error
}
func (e *UpdateNameError) Error() string {
return fmt.Sprintf("update name error : %v", e.Err)
}
func (e *UpdateNameError) Unwrap() error { return e.Err }
// NodeIDError is returned when a [NodeID] is invalid.
// The NodeID field is the node ID and the Err field is the cause.
type NodeIDError struct {
NodeID NodeID
Err error
}
func (e *NodeIDError) Error() string {
return fmt.Sprintf("node id error; node_id:%d : %v", e.NodeID, e.Err)
}
func (e *NodeIDError) Unwrap() error { return e.Err }
// CANIDError is returned when a [CANID] is invalid.
// The CANID field is the CAN-ID and the Err field is the cause.
type CANIDError struct {
CANID CANID
Err error
}
func (e *CANIDError) Error() string {
return fmt.Sprintf("can id error; can_id:%d : %v", e.CANID, e.Err)
}
func (e *CANIDError) Unwrap() error { return e.Err }
// MessageIDError is returned when a [MessageCANID] is invalid.
// The MessageID field is the message ID and the Err field is the cause.
type MessageIDError struct {
MessageID MessageID
Err error
}
func (e *MessageIDError) Error() string {
return fmt.Sprintf("message id error; message_id:%d : %v", e.MessageID, e.Err)
}
func (e *MessageIDError) Unwrap() error { return e.Err }
// GroupIDError is returned when a group ID is invalid.
// The GroupID field is the group ID and the Err field is the cause.
type GroupIDError struct {
GroupID int
Err error
}
func (e *GroupIDError) Error() string {
return fmt.Sprintf("group id error; group_id:%d : %v", e.GroupID, e.Err)
}
func (e *GroupIDError) Unwrap() error { return e.Err }
// InsertSignalError is returned when a signal cannot be inserted.
// The EntityID field is the ID of the signal, the Name field is the name,
// the StartBit field is the start bit, and the Err field is the cause.
type InsertSignalError struct {
EntityID EntityID
Name string
StartBit int
Err error
}
func (e *InsertSignalError) Error() string {
return fmt.Sprintf("insert signal error; entity_id:%q, name:%q, start_bit:%d : %v", e.EntityID.String(), e.Name, e.StartBit, e.Err)
}
func (e *InsertSignalError) Unwrap() error { return e.Err }
// AppendSignalError is returned when a signal cannot be appended.
// The EntityID field is the ID of the signal, the Name field is the name,
// and the Err field is the cause.
type AppendSignalError struct {
EntityID EntityID
Name string
Err error
}
func (e *AppendSignalError) Error() string {
return fmt.Sprintf("append signal error; entity_id:%q, name:%q : %v", e.EntityID.String(), e.Name, e.Err)
}
func (e *AppendSignalError) Unwrap() error { return e.Err }
// ConversionError is returned when a signal cannot be converted.
type ConversionError struct {
From string
To string
}
func (e *ConversionError) Error() string {
return fmt.Sprintf("conversion error; from:%q, to:%q", e.From, e.To)
}
// SignalSizeError is returned when a signal size is invalid.
// The Size field is the size and the Err field is the cause.
type SignalSizeError struct {
Size int
Err error
}
func (e *SignalSizeError) Error() string {
return fmt.Sprintf("signal size error; size:%d : %v", e.Size, e.Err)
}
func (e *SignalSizeError) Unwrap() error { return e.Err }
// StartBitError is returned when a start bit is invalid.
// The StartBit field is the start bit and the Err field is the cause.
type StartBitError struct {
StartBit int
Err error
}
func (e *StartBitError) Error() string {
return fmt.Sprintf("start bit error; start_bit:%d : %v", e.StartBit, e.Err)
}
func (e *StartBitError) Unwrap() error { return e.Err }
// UpdateIndexError is returned when an index cannot be updated.
// The Err field is the cause.
type UpdateIndexError struct {
Err error
}
func (e *UpdateIndexError) Error() string {
return fmt.Sprintf("update index value error : %v", e.Err)
}
func (e *UpdateIndexError) Unwrap() error { return e.Err }
// ValueIndexError is returned when a value index is invalid.
// The Index field is the index and the Err field is the cause.
type ValueIndexError struct {
Index int
Err error
}
func (e *ValueIndexError) Error() string {
return fmt.Sprintf("value index error; index:%d : %v", e.Index, e.Err)
}
func (e *ValueIndexError) Unwrap() error { return e.Err }
// AttributeValueError is returned when an attribute value is invalid.
// The Err field contains the cause.
type AttributeValueError struct {
Err error
}
func (e *AttributeValueError) Error() string {
return fmt.Sprintf("attribute value error : %v", e.Err)
}
func (e *AttributeValueError) Unwrap() error { return e.Err }
// EntityIDError is returned when an entity id is invalid.
// The EntityID field is the id of the entity and the Err field is the cause.
type EntityIDError struct {
EntityID EntityID
Err error
}
func (e *EntityIDError) Error() string {
return fmt.Sprintf("entity id error; entity_id:%q : %v", e.EntityID, e.Err)
}
func (e *EntityIDError) Unwrap() error { return e.Err }