-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
43 lines (39 loc) · 1.35 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
package beanstalkg
import "errors"
var (
InvalidTubeName = errors.New(`tube name exceeds 200 characters`)
UnexpectedResponse = errors.New(`unexpected result received from command`)
DeadlineSoon = errors.New(`deadline soon`)
TimedOut = errors.New(`timed out`)
ExpectedCRLF = errors.New(`expected CRLF`)
JobTooBig = errors.New(`job too big`)
Draining = errors.New(`draining`)
Buried = errors.New(`buried`)
NotFound = errors.New(`not found`)
OutOfMemory = errors.New(`out of memory`)
InternalError = errors.New(`internal error`)
BadFormat = errors.New(`bad format`)
UnknownCommand = errors.New(`unknown command`)
NotIgnored = errors.New(`not ignored`)
)
var errorMapping = map[string]error{
"DEADLINE_SOON\r\n": DeadlineSoon,
"TIMED_OUT\r\n": TimedOut,
"EXPECTED_CRLF\r\n": ExpectedCRLF,
"JOB_TOO_BIG\r\n": JobTooBig,
"DRAINING\r\n": Draining,
"BURIED\r\n": Buried,
"NOT_FOUND\r\n": NotFound,
"OUT_OF_MEMORY\r\n": OutOfMemory,
"INTERNAL_ERROR\r\n": InternalError,
"BAD_FORMAT\r\n": BadFormat,
"UNKNOWN_COMMAND\r\n": UnknownCommand,
"NOT_IGNORED\r\n": NotIgnored,
}
func stringToError(errorString string) error {
val, ok := errorMapping[errorString]
if ok {
return val
}
return UnexpectedResponse
}