Browse Source

checkpoint wip simplify errors slightly

Evan Huus 12 years ago
parent
commit
cbc1273e08
2 changed files with 7 additions and 11 deletions
  1. 3 3
      broker.go
  2. 4 8
      errors.go

+ 3 - 3
broker.go

@@ -101,7 +101,7 @@ func (b *broker) decode(pd packetDecoder) (err error) {
 		return err
 	}
 	if b.port > math.MaxUint16 {
-		return DecodingError{"Broker port > 65536"}
+		return DecodingError("Broker port > 65536")
 	}
 
 	err = b.connect()
@@ -141,13 +141,13 @@ func (b *broker) rcvResponseLoop() {
 		decoder := realDecoder{raw: header}
 		length, _ := decoder.getInt32()
 		if length <= 4 || length > 2*math.MaxUint16 {
-			b.forceDisconnect(&response, DecodingError{})
+			b.forceDisconnect(&response, DecodingError("Malformed length field."))
 			return
 		}
 
 		corr_id, _ := decoder.getInt32()
 		if response.correlation_id != corr_id {
-			b.forceDisconnect(&response, DecodingError{})
+			b.forceDisconnect(&response, DecodingError("Mismatched correlation id."))
 			return
 		}
 

+ 4 - 8
errors.go

@@ -63,18 +63,14 @@ func (err OutOfBrokers) Error() string {
 	return "kafka: Client has run out of available brokers to talk to. Is your cluster reachable?"
 }
 
-type EncodingError struct {
-	msg string
-}
+type EncodingError string
 
 func (err EncodingError) Error() string {
-	return "kafka: Could not encode packet. " + err.msg
+	return "kafka: Could not encode packet. " + string(err)
 }
 
-type DecodingError struct {
-	msg string
-}
+type DecodingError string
 
 func (err DecodingError) Error() string {
-	return "kafka: Could not decode packet. " + err.msg
+	return "kafka: Could not decode packet. " + string(err)
 }