kerr: always return *kerr.Error from ErrorForCode
This may make some workflows easier while still satisfying the `error`
return contract.
@@ -9,7 +9,7 @@ package kerr
import "fmt"
-// Error is a Kafka error.
+// Error is a Kafka error that implements the error interface.
type Error struct {
// Message is the string form of a Kafka error code
// (UNKNOWN_SERVER_ERROR, etc).
@@ -30,7 +30,9 @@ func (e *Error) Error() string {
//
// If the code is unknown, this returns UnknownServerError.
// If the code is 0, this returns nil.
-func ErrorForCode(code int16) error {
+//
+// The returned error implements the error interface.
+func ErrorForCode(code int16) *Error {
err, exists := code2err[code]
if !exists {
return UnknownServerError
@@ -148,7 +150,7 @@ var (
UnknownTopicID = &Error{"UNKNOWN_TOPIC_ID", 100, true, "This server does not host this topic ID."}
)
-var code2err = map[int16]error{
+var code2err = map[int16]*Error{
-1: UnknownServerError,
0: nil,
1: OffsetOutOfRange,
