-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkinds.go
181 lines (168 loc) · 3.08 KB
/
kinds.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
package errors
import "fmt"
type Kind uint16
// General
// 0 - 99
const (
Undefined Kind = iota
TimeOut
Network
FileNotFound
Retry
Stop
MaxJobs
QueueSize
)
// general errors
func generalSwitch(k Kind) string {
switch k {
case Undefined:
return "Undefined"
case TimeOut:
return "Timeout"
case Network:
return "Network"
case FileNotFound:
return "FileNotFound"
case Retry:
return "Retry"
case Stop:
return "Stop"
case MaxJobs:
return "MaxJobs"
case QueueSize:
return "QueueSize"
default:
return fmt.Sprintf("The error number is: %d, type is UNDEF", k)
}
}
// Endure Kinds of errors.
// 100 - 199
const (
Register Kind = iota + 100
Providers
Logger
ArgType
Init
Serve
Unsupported
Disabled
Traverse
FunctionCall
)
// error kinds related to the endure
func endureSwitch(k Kind) string {
switch k {
case Register:
return "Register error"
case Providers:
return "Providers error"
case Logger:
return "Logger error"
case Init:
return "Init error"
case Serve:
return "Serve error"
case Disabled:
return "Vertex disabled"
case ArgType:
return "Wrong arg type, or return type"
case Traverse:
return "Traverse error"
case FunctionCall:
return "Function call error"
case Unsupported:
return "Unsupported"
default:
return fmt.Sprintf("The error number is: %d, type is UNDEF", k)
}
}
// RR core kinds
// 200 - 299
const (
WatcherStopped Kind = iota + 200
SoftJob
WorkerAllocate
NoFreeWorkers
Encode
Decode
ExecTTL
IdleTTL
TTL
)
// error kinds related to the rr core
func rrSwitch(k Kind) string {
switch k {
case WatcherStopped:
return "Workers watcher stopped"
case SoftJob:
return "SoftJobError"
case NoFreeWorkers:
return "NoFreeWorkers"
case WorkerAllocate:
return "WorkerAllocate"
case ExecTTL:
return "ExecTTL"
case IdleTTL:
return "IdleTTL"
case TTL:
return "TTL"
case Encode:
return "Encode"
case Decode:
return "Decode"
default:
return fmt.Sprintf("The error number is: %d, type is UNDEF", k)
}
}
// RR plugins kinds
// 300 - 399
const (
// kv plugin
EmptyKey Kind = iota + 300
EmptyItem
NoKeys
NoSuchBucket
BucketShouldBeSet
NoConfig
// Reload plugin
SkipFile
NoWalkerConfig
)
// error kinds related to the rr plugins
func rrPluginsSw(k Kind) string {
switch k {
case SkipFile:
return "SkipFile"
case NoWalkerConfig:
return "NoWalkerConfig"
case EmptyKey:
return "key can't be empty string"
case EmptyItem:
return "empty Item"
case NoKeys:
return "should provide at least 1 key"
case NoSuchBucket:
return "no such bucket"
case BucketShouldBeSet:
return "bucket should be set"
case NoConfig:
return "no config provided"
default:
return fmt.Sprintf("The error number is: %d, type is UNDEF", k)
}
}
func (k Kind) String() string {
switch {
case k < 100: // 0-99 general
return generalSwitch(k)
case k >= 100 && k < 200: // 100-199, endure
return endureSwitch(k)
case k >= 200 && k < 300: // 200-299, rr
return rrSwitch(k)
case k >= 300 && k < 400: // 300-399, plugins
return rrPluginsSw(k)
default:
return fmt.Sprintf("The error number is: %d, type is UNDEF", k)
}
}