-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstore_errors.go
More file actions
76 lines (68 loc) · 1.26 KB
/
store_errors.go
File metadata and controls
76 lines (68 loc) · 1.26 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
package errors
import "fmt"
// StoreErrType ...
type StoreErrType uint32
const (
// KeyNotFound ...
KeyNotFound StoreErrType = iota
// TooLate ...
TooLate
// PassedIndex ...
PassedIndex
// SkippedIndex ...
SkippedIndex
// NoRoot ...
NoRoot
// UnknownParticipant ...
UnknownParticipant
// Empty ...
Empty
// KeyAlreadyExists ...
KeyAlreadyExists
// NoPeerSet ...
NoPeerSet
)
// StoreErr ...
type StoreErr struct {
dataType string
errType StoreErrType
key string
}
// NewStoreErr ...
func NewStoreErr(dataType string, errType StoreErrType, key string) StoreErr {
return StoreErr{
dataType: dataType,
errType: errType,
key: key,
}
}
// Error ...
func (e StoreErr) Error() string {
m := ""
switch e.errType {
case KeyNotFound:
m = "Not Found"
case TooLate:
m = "Too Late"
case PassedIndex:
m = "Passed Index"
case SkippedIndex:
m = "Skipped Index"
case NoRoot:
m = "No Root"
case UnknownParticipant:
m = "Unknown Participant"
case Empty:
m = "Empty"
case KeyAlreadyExists:
m = "Key Already Exists"
case NoPeerSet:
m = "No PeerSet"
}
return fmt.Sprintf("%s, %s, %s", e.dataType, e.key, m)
}
// Is ...
func Is(err error, t StoreErrType) bool {
storeErr, ok := err.(StoreErr)
return ok && storeErr.errType == t
}