/
error.go
58 lines (47 loc) · 1.46 KB
/
error.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
package skiplistmap
import (
"fmt"
)
type ErrType uint16
const (
EIItemInvalidAdd ErrType = 1 << iota
EBucketNotFound
EBucketAllocatedFail
EBucketInvalid
EBucketInvalidOrder
EBucketAlreadyExist
EIndexOverflow
EIPoolAlreadyDeleted
EIPooExpandFail
)
var (
ErrItemInvalidAdd error = NewError(EIItemInvalidAdd, "dd: item is added. but not found", nil)
ErrBucketNotFound error = NewError(EBucketNotFound, "bucket is not found", nil)
ErrBucketAllocatedFail error = NewError(EBucketAllocatedFail, "cannot allocated level bucket buffer", nil)
ErrBucketAlreadyExit error = NewError(EBucketAlreadyExist, "bucket is exist alread", nil)
ErrBucketInvalidOrder error = NewError(EBucketInvalidOrder, "bucket is invalid order", nil)
ErrIdxOverflow error = NewError(EIndexOverflow, "index overflow for slice", nil)
EPoolAlreadyDeleted error = NewError(EIPoolAlreadyDeleted, "itemPool already deleted", nil)
EPoolExpandFail error = NewError(EIPooExpandFail, "fail expand itemPool", nil)
)
type Error struct {
Type ErrType
message string
error error
}
func NewError(t ErrType, m string, e error) *Error {
return &Error{
Type: t,
message: m,
error: e,
}
}
func (e *Error) Error() string {
if e.error == nil {
return fmt.Sprintf("type: %v message: %s", e.Type, e.message)
}
return fmt.Sprintf("type: %v message: %s error: %s", e.Type, e.message, e.error.Error())
}
func (e *Error) ErrorNum() uint16 {
return uint16(e.Type)
}