forked from docker-archive/go-redis-server
-
Notifications
You must be signed in to change notification settings - Fork 3
/
error.go
39 lines (32 loc) · 1.06 KB
/
error.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
package redis
import (
"errors"
"io"
)
var (
ErrMethodNotSupported = NewError("Method is not supported")
ErrNotEnoughArgs = NewError("Not enough arguments for the command")
ErrTooMuchArgs = NewError("Too many arguments for the command")
ErrWrongArgsNumber = NewError("Wrong number of arguments")
ErrExpectInteger = NewError("Expected integer")
ErrExpectPositivInteger = NewError("Expected positive integer")
ErrExpectMorePair = NewError("Expected at least one key val pair")
ErrExpectEvenPair = NewError("Got uneven number of key val pairs")
)
var (
ErrParseTimeout = errors.New("timeout is not an integer or out of range")
)
type ErrorReply struct {
code string
message string
}
func (er *ErrorReply) WriteTo(w io.Writer) (int64, error) {
n, err := w.Write([]byte("-" + er.code + " " + er.message + "\r\n"))
return int64(n), err
}
func (er *ErrorReply) Error() string {
return "-" + er.code + " " + er.message + "\r\n"
}
func NewError(message string) *ErrorReply {
return &ErrorReply{code: "ERROR", message: message}
}