-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
93 lines (76 loc) · 2.21 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
package jackd
import (
"errors"
"strings"
)
var NoErrs = make([]string, 0)
var TubeNameTooBig = errors.New("tube name over 200 bytes")
func validateTubeName(tube string) error {
tubeNameBytes := []byte(tube)
if len(tubeNameBytes) > MaxTubeName {
return TubeNameTooBig
}
return nil
}
func validate(resp string, additionalErrorStrings []string) error {
errorStrings := append(
/* Generic command errors */
[]string{OutOfMemory, InternalError, BadFormat, UnknownCommand},
additionalErrorStrings...,
)
for _, errorString := range errorStrings {
if strings.HasPrefix(resp, errorString) {
if err, ok := errorMap[errorString]; ok {
return err
}
return errors.New(errorString)
}
}
return nil
}
//goland:noinspection ALL
var (
/* Generic command errors */
OutOfMemory = "OUT_OF_MEMORY"
ErrOutOfMemory = errors.New("out of memory")
InternalError = "INTERNAL_ERROR"
ErrInternalError = errors.New("internal error")
BadFormat = "BAD_FORMAT"
ErrBadFormat = errors.New("bad format")
UnknownCommand = "UNKNOWN_COMMAND"
ErrUnknownCommand = errors.New("unknown command")
/* Reservation errors */
DeadlineSoon = "DEADLINE_SOON"
ErrDeadlineSoon = errors.New("deadline soon")
TimedOut = "TIMED_OUT"
ErrTimedOut = errors.New("timed out")
/* Put errors */
Buried = "BURIED"
ErrBuried = errors.New("job buried")
ExpectedCRLF = "EXPECTED_CRLF"
ErrExpectedCRLF = errors.New("put command expects CRLF")
JobTooBig = "JOB_TOO_BIG"
ErrJobTooBig = errors.New("job is too big")
Draining = "DRAINING"
ErrDraining = errors.New("tube is draining")
/* Delete errors */
NotFound = "NOT_FOUND"
ErrNotFound = errors.New("job not found")
/* Ignore errors */
NotIgnored = "NOT_IGNORED"
ErrNotIgnored = errors.New("tube not ignored")
)
var errorMap = map[string]error{
OutOfMemory: ErrOutOfMemory,
InternalError: ErrInternalError,
BadFormat: ErrBadFormat,
UnknownCommand: ErrUnknownCommand,
DeadlineSoon: ErrDeadlineSoon,
TimedOut: ErrTimedOut,
Buried: ErrBuried,
ExpectedCRLF: ErrExpectedCRLF,
JobTooBig: ErrJobTooBig,
Draining: ErrDraining,
NotFound: ErrNotFound,
NotIgnored: ErrNotIgnored,
}