Repository: kafka Updated Branches: refs/heads/trunk e43c9aff9 -> b7bd2978d
KAFKA-2100; Client Error doesn't preserve or display original server error code when it is an unknown code; Reviewed by Gwen, Guozhang and Ewen Project: http://git-wip-us.apache.org/repos/asf/kafka/repo Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/b7bd2978 Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/b7bd2978 Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/b7bd2978 Branch: refs/heads/trunk Commit: b7bd2978dc3947297fefc06ff9b22949d5bd1b50 Parents: e43c9af Author: David Jacot <david.ja...@gmail.com> Authored: Wed Jul 29 10:34:42 2015 -0700 Committer: Gwen Shapira <csh...@gmail.com> Committed: Wed Jul 29 10:34:42 2015 -0700 ---------------------------------------------------------------------- .../java/org/apache/kafka/common/protocol/Errors.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kafka/blob/b7bd2978/clients/src/main/java/org/apache/kafka/common/protocol/Errors.java ---------------------------------------------------------------------- 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<Class<?>, Errors> classToError = new HashMap<Class<?>, Errors>(); private static Map<Short, Errors> codeToError = new HashMap<Short, Errors>(); @@ -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());