From c38ed03cc64018c4d21e2193dc792fc6267957a8 Mon Sep 17 00:00:00 2001 From: David Jacot Date: Mon, 27 Jul 2015 07:36:39 +0200 Subject: [PATCH] KAFKA-2100; Client Error doesn't preserve or display original server error code when it is an unknown code. --- .../main/java/org/apache/kafka/common/protocol/Errors.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/clients/src/main/java/org/apache/kafka/common/protocol/Errors.java b/clients/src/main/java/org/apache/kafka/common/protocol/Errors.java index d6c41c1..e17e390 100644 --- a/clients/src/main/java/org/apache/kafka/common/protocol/Errors.java +++ b/clients/src/main/java/org/apache/kafka/common/protocol/Errors.java @@ -20,6 +20,8 @@ import java.util.HashMap; import java.util.Map; import org.apache.kafka.common.errors.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * This class contains all the client-server errors--those errors that must be sent from the server to the client. These @@ -83,6 +85,8 @@ public enum Errors { INVALID_COMMIT_OFFSET_SIZE(28, new ApiException("The committing offset data size is not valid")); + private static final Logger log = LoggerFactory.getLogger(Errors.class); + private static Map, Errors> classToError = new HashMap, Errors>(); private static Map codeToError = new HashMap(); @@ -130,11 +134,16 @@ public enum Errors { */ public static Errors forCode(short code) { Errors error = codeToError.get(code); - return error == null ? UNKNOWN : error; + if (error != null) { + return error; + } else { + log.warn("Unexpected error code: {}.", code); + return UNKNOWN; + } } /** - * Return the error instance associated with this exception (or UKNOWN if there is none) + * Return the error instance associated with this exception (or UNKNOWN if there is none) */ public static Errors forException(Throwable t) { Errors error = classToError.get(t.getClass()); -- 2.3.2 (Apple Git-55)