فهرست منبع

Add note about concurrency to error messages.

Gary Burd 11 سال پیش
والد
کامیت
08550c8cc5
1فایلهای تغییر یافته به همراه16 افزوده شده و 10 حذف شده
  1. 16 10
      redis/conn.go

+ 16 - 10
redis/conn.go

@@ -191,17 +191,23 @@ func (c *conn) writeCommand(cmd string, args []interface{}) (err error) {
 	return err
 }
 
+type protocolError string
+
+func (pe protocolError) Error() string {
+	return fmt.Sprintf("redigo: %s (possible server error or unsupported concurrent read by application)", string(pe))
+}
+
 func (c *conn) readLine() ([]byte, error) {
 	p, err := c.br.ReadSlice('\n')
 	if err == bufio.ErrBufferFull {
-		return nil, errors.New("redigo: long response line")
+		return nil, protocolError("long response line")
 	}
 	if err != nil {
 		return nil, err
 	}
 	i := len(p) - 2
 	if i < 0 || p[i] != '\r' {
-		return nil, errors.New("redigo: bad response line terminator")
+		return nil, protocolError("bad response line terminator")
 	}
 	return p[:i], nil
 }
@@ -209,7 +215,7 @@ func (c *conn) readLine() ([]byte, error) {
 // parseLen parses bulk string and array lengths.
 func parseLen(p []byte) (int, error) {
 	if len(p) == 0 {
-		return -1, errors.New("redigo: malformed length")
+		return -1, protocolError("malformed length")
 	}
 
 	if p[0] == '-' && len(p) == 2 && p[1] == '1' {
@@ -221,7 +227,7 @@ func parseLen(p []byte) (int, error) {
 	for _, b := range p {
 		n *= 10
 		if b < '0' || b > '9' {
-			return -1, errors.New("redigo: illegal bytes in length")
+			return -1, protocolError("illegal bytes in length")
 		}
 		n += int(b - '0')
 	}
@@ -232,7 +238,7 @@ func parseLen(p []byte) (int, error) {
 // parseInt parses an integer reply.
 func parseInt(p []byte) (interface{}, error) {
 	if len(p) == 0 {
-		return 0, errors.New("redigo: malformed integer")
+		return 0, protocolError("malformed integer")
 	}
 
 	var negate bool
@@ -240,7 +246,7 @@ func parseInt(p []byte) (interface{}, error) {
 		negate = true
 		p = p[1:]
 		if len(p) == 0 {
-			return 0, errors.New("redigo: malformed integer")
+			return 0, protocolError("malformed integer")
 		}
 	}
 
@@ -248,7 +254,7 @@ func parseInt(p []byte) (interface{}, error) {
 	for _, b := range p {
 		n *= 10
 		if b < '0' || b > '9' {
-			return 0, errors.New("redigo: illegal bytes in length")
+			return 0, protocolError("illegal bytes in length")
 		}
 		n += int64(b - '0')
 	}
@@ -270,7 +276,7 @@ func (c *conn) readReply() (interface{}, error) {
 		return nil, err
 	}
 	if len(line) == 0 {
-		return nil, errors.New("redigo: short response line")
+		return nil, protocolError("short response line")
 	}
 	switch line[0] {
 	case '+':
@@ -301,7 +307,7 @@ func (c *conn) readReply() (interface{}, error) {
 		if line, err := c.readLine(); err != nil {
 			return nil, err
 		} else if len(line) != 0 {
-			return nil, errors.New("redigo: bad bulk string format")
+			return nil, protocolError("bad bulk string format")
 		}
 		return p, nil
 	case '*':
@@ -318,7 +324,7 @@ func (c *conn) readReply() (interface{}, error) {
 		}
 		return r, nil
 	}
-	return nil, errors.New("redigo: unexpected response line")
+	return nil, protocolError("unexpected response line")
 }
 
 func (c *conn) Send(cmd string, args ...interface{}) error {