-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.go
46 lines (42 loc) · 1.38 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
package mc
import (
"errors"
"fmt"
"github.com/kinescope/mc/protocol"
)
var (
ErrCacheMiss = errors.New("memcache: cache miss")
ErrNotStored = errors.New("memcache: item not stored")
ErrNoServers = errors.New("memcache: no servers configured or available")
ErrBadIncrDec = errors.New("memcache: incr or decr on non-numeric value")
ErrCASConflict = errors.New("memcache: compare-and-swap conflict")
ErrServerError = errors.New("memcache: server error")
ErrMalformedKey = errors.New("memcache: key is too long or contains invalid characters")
ErrAlreadyExists = errors.New("memcache: item already exists")
ErrValueTooLarge = errors.New("memcache: value too large")
ErrInvalidArguments = errors.New("memcache: invalid arguments")
)
func checkError(err error) error {
switch e := err.(type) {
case protocol.Status:
switch e {
case protocol.StatusKeyExists:
return ErrAlreadyExists
case protocol.StatusKeyNotFound:
return ErrCacheMiss
case protocol.StatusItemNotStored:
return ErrNotStored
case protocol.StatusInternalError:
return ErrServerError
case protocol.StatusInvalidArguments:
return ErrInvalidArguments
case protocol.StatusIncrDecrOnNonNumericValue:
return ErrBadIncrDec
case protocol.StatusValueTooLarge:
return ErrValueTooLarge
default:
return fmt.Errorf("memcache: status=%d", e)
}
}
return err
}