Переглянути джерело

Cleanup a bunch more error formats

Evan Huus 10 роки тому
батько
коміт
66411d8222
9 змінених файлів з 22 додано та 22 видалено
  1. 1 1
      broker.go
  2. 2 2
      encoder_decoder.go
  3. 3 3
      errors.go
  4. 1 1
      length_field.go
  5. 3 3
      message.go
  6. 4 4
      prep_encoder.go
  7. 5 5
      real_decoder.go
  8. 2 2
      request.go
  9. 1 1
      response_header.go

+ 1 - 1
broker.go

@@ -359,7 +359,7 @@ func (b *Broker) responseReceiver() {
 		if decodedHeader.correlationID != response.correlationID {
 			// TODO if decoded ID < cur ID, discard until we catch up
 			// TODO if decoded ID > cur ID, save it so when cur ID catches up we have a response
-			response.errors <- PacketDecodingError{fmt.Sprintf("CorrelationID didn't match, wanted %d, got %d", response.correlationID, decodedHeader.correlationID)}
+			response.errors <- PacketDecodingError{fmt.Sprintf("correlation ID didn't match, wanted %d, got %d", response.correlationID, decodedHeader.correlationID)}
 			continue
 		}
 

+ 2 - 2
encoder_decoder.go

@@ -23,7 +23,7 @@ func encode(e encoder) ([]byte, error) {
 	}
 
 	if prepEnc.length < 0 || prepEnc.length > int(MaxRequestSize) {
-		return nil, PacketEncodingError{fmt.Sprintf("Invalid request size: %d", prepEnc.length)}
+		return nil, PacketEncodingError{fmt.Sprintf("invalid request size (%d)", prepEnc.length)}
 	}
 
 	realEnc.raw = make([]byte, prepEnc.length)
@@ -55,7 +55,7 @@ func decode(buf []byte, in decoder) error {
 	}
 
 	if helper.off != len(buf) {
-		return PacketDecodingError{"Length was invalid"}
+		return PacketDecodingError{"invalid length"}
 	}
 
 	return nil

+ 3 - 3
errors.go

@@ -7,7 +7,7 @@ import (
 
 // ErrOutOfBrokers is the error returned when the client has run out of brokers to talk to because all of them errored
 // or otherwise failed to respond.
-var ErrOutOfBrokers = errors.New("kafka: Client has run out of available brokers to talk to. Is your cluster reachable?")
+var ErrOutOfBrokers = errors.New("kafka: client has run out of available brokers to talk to (Is your cluster reachable?)")
 
 // ErrClosedClient is the error returned when a method is called on a client that has been closed.
 var ErrClosedClient = errors.New("kafka: tried to use a client that was closed")
@@ -44,7 +44,7 @@ type PacketEncodingError struct {
 }
 
 func (err PacketEncodingError) Error() string {
-	return fmt.Sprintf("kafka: Error while encoding packet: %s", err.Info)
+	return fmt.Sprintf("kafka: error encoding packet: %s", err.Info)
 }
 
 // PacketDecodingError is returned when there was an error (other than truncated data) decoding the Kafka broker's response.
@@ -54,7 +54,7 @@ type PacketDecodingError struct {
 }
 
 func (err PacketDecodingError) Error() string {
-	return fmt.Sprintf("kafka: Error while decoding packet: %s", err.Info)
+	return fmt.Sprintf("kafka: error decoding packet: %s", err.Info)
 }
 
 // ConfigurationError is the type of error returned from a constructor (e.g. NewClient, or NewConsumer)

+ 1 - 1
length_field.go

@@ -22,7 +22,7 @@ func (l *lengthField) run(curOffset int, buf []byte) error {
 
 func (l *lengthField) check(curOffset int, buf []byte) error {
 	if uint32(curOffset-l.startOffset-4) != binary.BigEndian.Uint32(buf[l.startOffset:]) {
-		return PacketDecodingError{"Lengthfield check failed"}
+		return PacketDecodingError{"length field invalid"}
 	}
 
 	return nil

+ 3 - 3
message.go

@@ -70,7 +70,7 @@ func (m *Message) encode(pe packetEncoder) error {
 			m.compressedCache = tmp
 			payload = m.compressedCache
 		default:
-			return PacketEncodingError{fmt.Sprintf("Unsupported compression codec: %d", m.Codec)}
+			return PacketEncodingError{fmt.Sprintf("unsupported compression codec (%d)", m.Codec)}
 		}
 	}
 
@@ -92,7 +92,7 @@ func (m *Message) decode(pd packetDecoder) (err error) {
 		return err
 	}
 	if format != messageFormat {
-		return PacketDecodingError{"Unexpected messageFormat"}
+		return PacketDecodingError{"unexpected messageFormat"}
 	}
 
 	attribute, err := pd.getInt8()
@@ -135,7 +135,7 @@ func (m *Message) decode(pd packetDecoder) (err error) {
 		}
 		return m.decodeSet()
 	default:
-		return PacketDecodingError{fmt.Sprintf("Invalid compression specified: %d", m.Codec)}
+		return PacketDecodingError{fmt.Sprintf("invalid compression specified (%d)", m.Codec)}
 	}
 
 	err = pd.pop()

+ 4 - 4
prep_encoder.go

@@ -29,7 +29,7 @@ func (pe *prepEncoder) putInt64(in int64) {
 
 func (pe *prepEncoder) putArrayLength(in int) error {
 	if in > math.MaxInt32 {
-		return PacketEncodingError{fmt.Sprintf("Array too long: %d", in)}
+		return PacketEncodingError{fmt.Sprintf("array too long (%d)", in)}
 	}
 	pe.length += 4
 	return nil
@@ -43,7 +43,7 @@ func (pe *prepEncoder) putBytes(in []byte) error {
 		return nil
 	}
 	if len(in) > math.MaxInt32 {
-		return PacketEncodingError{fmt.Sprintf("Byteslice too long: %d", len(in))}
+		return PacketEncodingError{fmt.Sprintf("byteslice too long (%d)", len(in))}
 	}
 	pe.length += len(in)
 	return nil
@@ -51,7 +51,7 @@ func (pe *prepEncoder) putBytes(in []byte) error {
 
 func (pe *prepEncoder) putRawBytes(in []byte) error {
 	if len(in) > math.MaxInt32 {
-		return PacketEncodingError{fmt.Sprintf("Byteslice too long: %d", len(in))}
+		return PacketEncodingError{fmt.Sprintf("byteslice too long (%d)", len(in))}
 	}
 	pe.length += len(in)
 	return nil
@@ -60,7 +60,7 @@ func (pe *prepEncoder) putRawBytes(in []byte) error {
 func (pe *prepEncoder) putString(in string) error {
 	pe.length += 2
 	if len(in) > math.MaxInt16 {
-		return PacketEncodingError{fmt.Sprintf("String too long: %d", len(in))}
+		return PacketEncodingError{fmt.Sprintf("string too long (%d)", len(in))}
 	}
 	pe.length += len(in)
 	return nil

+ 5 - 5
real_decoder.go

@@ -64,7 +64,7 @@ func (rd *realDecoder) getArrayLength() (int, error) {
 		rd.off = len(rd.raw)
 		return -1, ErrInsufficientData
 	} else if tmp > 2*math.MaxUint16 {
-		return -1, PacketDecodingError{"getArrayLength failed: Invalid array length"}
+		return -1, PacketDecodingError{"invalid array length"}
 	}
 	return tmp, nil
 }
@@ -82,7 +82,7 @@ func (rd *realDecoder) getBytes() ([]byte, error) {
 
 	switch {
 	case n < -1:
-		return nil, PacketDecodingError{"getBytes failed: Invalid length"}
+		return nil, PacketDecodingError{"invalid byteslice length"}
 	case n == -1:
 		return nil, nil
 	case n == 0:
@@ -108,7 +108,7 @@ func (rd *realDecoder) getString() (string, error) {
 
 	switch {
 	case n < -1:
-		return "", PacketDecodingError{"getString failed: invalid length"}
+		return "", PacketDecodingError{"invalid string length"}
 	case n == -1:
 		return "", nil
 	case n == 0:
@@ -141,7 +141,7 @@ func (rd *realDecoder) getInt32Array() ([]int32, error) {
 	}
 
 	if n < 0 {
-		return nil, PacketDecodingError{"getInt32Array failed: invalid length"}
+		return nil, PacketDecodingError{"invalid array length"}
 	}
 
 	ret := make([]int32, n)
@@ -170,7 +170,7 @@ func (rd *realDecoder) getInt64Array() ([]int64, error) {
 	}
 
 	if n < 0 {
-		return nil, PacketDecodingError{"getInt64Array failed: invalid length"}
+		return nil, PacketDecodingError{"invalid array length"}
 	}
 
 	ret := make([]int64, n)

+ 2 - 2
request.go

@@ -51,7 +51,7 @@ func (r *request) decode(pd packetDecoder) (err error) {
 
 	r.body = allocateBody(key, version)
 	if r.body == nil {
-		return PacketDecodingError{fmt.Sprintf("Unknown request key: %d", key)}
+		return PacketDecodingError{fmt.Sprintf("unknown request key (%d)", key)}
 	}
 	return r.body.decode(pd)
 }
@@ -64,7 +64,7 @@ func decodeRequest(r io.Reader) (req *request, err error) {
 
 	length := int32(binary.BigEndian.Uint32(lengthBytes))
 	if length <= 4 || length > MaxRequestSize {
-		return nil, PacketDecodingError{fmt.Sprintf("Message of length %d too large or too small", length)}
+		return nil, PacketDecodingError{fmt.Sprintf("message of length %d too large or too small", length)}
 	}
 
 	encodedReq := make([]byte, length)

+ 1 - 1
response_header.go

@@ -13,7 +13,7 @@ func (r *responseHeader) decode(pd packetDecoder) (err error) {
 		return err
 	}
 	if r.length <= 4 || r.length > MaxResponseSize {
-		return PacketDecodingError{fmt.Sprintf("Message of length %d too large or too small", r.length)}
+		return PacketDecodingError{fmt.Sprintf("message of length %d too large or too small", r.length)}
 	}
 
 	r.correlationID, err = pd.getInt32()