sqoop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jar...@apache.org
Subject sqoop git commit: SQOOP-2765: Sqoop2: Client is not exposing the real exception when retrieving exception from server
Date Mon, 04 Jan 2016 14:01:28 GMT
Repository: sqoop
Updated Branches:
  refs/heads/sqoop2 fc1b1f950 -> 8d97bb3e2


SQOOP-2765: Sqoop2: Client is not exposing the real exception when retrieving exception from
server

(Dian Fu via Jarek Jarcec Cecho)


Project: http://git-wip-us.apache.org/repos/asf/sqoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/sqoop/commit/8d97bb3e
Tree: http://git-wip-us.apache.org/repos/asf/sqoop/tree/8d97bb3e
Diff: http://git-wip-us.apache.org/repos/asf/sqoop/diff/8d97bb3e

Branch: refs/heads/sqoop2
Commit: 8d97bb3e28db64f1b89e2ab80de8a0317d195bfd
Parents: fc1b1f9
Author: Jarek Jarcec Cecho <jarcec@apache.org>
Authored: Mon Jan 4 06:01:03 2016 -0800
Committer: Jarek Jarcec Cecho <jarcec@apache.org>
Committed: Mon Jan 4 06:01:03 2016 -0800

----------------------------------------------------------------------
 .../org/apache/sqoop/error/code/SqoopError.java | 40 ++++++++++++++++++++
 .../org/apache/sqoop/json/ThrowableBean.java    | 20 +++++-----
 .../apache/sqoop/json/TestThrowableBean.java    |  4 +-
 .../sqoop/shell/utils/ThrowableDisplayer.java   |  4 +-
 4 files changed, 53 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/sqoop/blob/8d97bb3e/common/src/main/java/org/apache/sqoop/error/code/SqoopError.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/error/code/SqoopError.java b/common/src/main/java/org/apache/sqoop/error/code/SqoopError.java
new file mode 100644
index 0000000..0c63671
--- /dev/null
+++ b/common/src/main/java/org/apache/sqoop/error/code/SqoopError.java
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sqoop.error.code;
+
+import org.apache.sqoop.common.ErrorCode;
+
+public class SqoopError implements ErrorCode {
+  private String errorCode;
+  private String errorCodeMessage;
+
+  public SqoopError(String errorCode, String errorCodeMessage) {
+    this.errorCode = errorCode;
+    this.errorCodeMessage = errorCodeMessage;
+  }
+
+  @Override
+  public String getCode() {
+    return errorCode;
+  }
+
+  @Override
+  public String getMessage() {
+    return errorCodeMessage;
+  }
+}

http://git-wip-us.apache.org/repos/asf/sqoop/blob/8d97bb3e/common/src/main/java/org/apache/sqoop/json/ThrowableBean.java
----------------------------------------------------------------------
diff --git a/common/src/main/java/org/apache/sqoop/json/ThrowableBean.java b/common/src/main/java/org/apache/sqoop/json/ThrowableBean.java
index 7748247..4c58b8f 100644
--- a/common/src/main/java/org/apache/sqoop/json/ThrowableBean.java
+++ b/common/src/main/java/org/apache/sqoop/json/ThrowableBean.java
@@ -19,7 +19,9 @@ package org.apache.sqoop.json;
 
 import org.apache.sqoop.classification.InterfaceAudience;
 import org.apache.sqoop.classification.InterfaceStability;
+import org.apache.sqoop.common.ErrorCode;
 import org.apache.sqoop.common.SqoopException;
+import org.apache.sqoop.error.code.SqoopError;
 import org.apache.sqoop.utils.ClassUtils;
 import org.json.simple.JSONArray;
 import org.json.simple.JSONObject;
@@ -42,7 +44,7 @@ public class ThrowableBean implements JsonBean {
   public static final String LINE = "line";
   public static final String CAUSE = "cause";
   public static final String ERROR_CODE = "error-code";
-  public static final String ERROR_CODE_CLASS = "error-code-class";
+  public static final String ERROR_CODE_MESSAGE = "error-code-message";
 
   private Throwable throwable;
 
@@ -70,7 +72,7 @@ public class ThrowableBean implements JsonBean {
     if(throwable instanceof SqoopException ) {
       SqoopException sqoopException = (SqoopException) throwable;
       result.put(ERROR_CODE, sqoopException.getErrorCode().getCode());
-      result.put(ERROR_CODE_CLASS, sqoopException.getErrorCode().getClass().getName());
+      result.put(ERROR_CODE_MESSAGE, sqoopException.getErrorCode().getMessage());
       // Override message with the original message
       result.put(MESSAGE, sqoopException.getOriginalMessage());
     }
@@ -107,15 +109,11 @@ public class ThrowableBean implements JsonBean {
     }
 
     // Special handling for SqoopException as we need to transfer ERROR_CODE from the other
side
-    if(jsonObject.containsKey(ERROR_CODE_CLASS)) {
-      Class e = ClassUtils.loadClass((String) jsonObject.get(ERROR_CODE_CLASS));
-
-      // Only if the error code class is known to this JVM, let's instantiate the real SqoopException
-      if( e != null) {
-        String errorCode = (String) jsonObject.get(ERROR_CODE);
-        Enum enumValue = Enum.valueOf(e, errorCode);
-        throwable = (Throwable) ClassUtils.instantiate(exceptionClass, enumValue, message);
-      }
+    if(jsonObject.containsKey(ERROR_CODE)) {
+      String errorCode = (String) jsonObject.get(ERROR_CODE);
+      String errorCodeMessage = (String) jsonObject.get(ERROR_CODE_MESSAGE);
+      ErrorCode code = new SqoopError(errorCode, errorCodeMessage);
+      throwable = (Throwable) ClassUtils.instantiate(exceptionClass, code, message);
     }
 
     // Let's try to instantiate same class that was originally on remote side.

http://git-wip-us.apache.org/repos/asf/sqoop/blob/8d97bb3e/common/src/test/java/org/apache/sqoop/json/TestThrowableBean.java
----------------------------------------------------------------------
diff --git a/common/src/test/java/org/apache/sqoop/json/TestThrowableBean.java b/common/src/test/java/org/apache/sqoop/json/TestThrowableBean.java
index e557519..ce973e3 100644
--- a/common/src/test/java/org/apache/sqoop/json/TestThrowableBean.java
+++ b/common/src/test/java/org/apache/sqoop/json/TestThrowableBean.java
@@ -53,8 +53,8 @@ public class TestThrowableBean {
     assertNotNull(retrieved);
     assertEquals(SqoopException.class, retrieved.getClass());
     SqoopException sqoopRetrieved = (SqoopException) retrieved;
-    assertEquals(SerializationError.class, sqoopRetrieved.getErrorCode().getClass());
-    assertEquals(SerializationError.SERIALIZATION_001, sqoopRetrieved.getErrorCode());
+    assertEquals(SerializationError.SERIALIZATION_001.getCode(), sqoopRetrieved.getErrorCode().getCode());
+    assertEquals(SerializationError.SERIALIZATION_001.getMessage(), sqoopRetrieved.getErrorCode().getMessage());
     assertEquals("SERIALIZATION_001:Attempt to pass a non-map object to MAP type. - Secret",
sqoopRetrieved.getMessage());
   }
 

http://git-wip-us.apache.org/repos/asf/sqoop/blob/8d97bb3e/shell/src/main/java/org/apache/sqoop/shell/utils/ThrowableDisplayer.java
----------------------------------------------------------------------
diff --git a/shell/src/main/java/org/apache/sqoop/shell/utils/ThrowableDisplayer.java b/shell/src/main/java/org/apache/sqoop/shell/utils/ThrowableDisplayer.java
index b9c8cad..79453d9 100644
--- a/shell/src/main/java/org/apache/sqoop/shell/utils/ThrowableDisplayer.java
+++ b/shell/src/main/java/org/apache/sqoop/shell/utils/ThrowableDisplayer.java
@@ -68,9 +68,9 @@ public class ThrowableDisplayer {
    */
   protected static void printThrowable(Throwable t, boolean verbose) {
     print("@|red Exception: |@");
-    print(t.getClass().getName());
+    print(t.getCause() == null ? t.getClass().getName() : t.getCause().getClass().getName());
     print(" @|red Message: |@");
-    print(t.getMessage());
+    print(t.getCause() == null ? t.getMessage() : t.getCause().getMessage());
     println();
 
     if(verbose) {


Mime
View raw message