PHOENIX-2396 Set root cause exception when parsing server exception

Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/519f9e05
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/519f9e05
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/519f9e05

Branch: refs/heads/txn
Commit: 519f9e0561b42d3499dec9c1247a1050fa26a78b
Parents: 8a5046e
Author: James Taylor <[email protected]>
Authored: Tue Nov 10 16:27:12 2015 -0800
Committer: James Taylor <[email protected]>
Committed: Tue Nov 10 16:27:12 2015 -0800

----------------------------------------------------------------------
 .../apache/phoenix/exception/SQLExceptionCode.java   |  5 ++---
 .../java/org/apache/phoenix/util/ServerUtil.java     | 15 +++++----------
 2 files changed, 7 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/519f9e05/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java 
b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
index 53a13be..cc0d0ed 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java
@@ -418,11 +418,10 @@ public enum SQLExceptionCode {
         }
     }
     
-    public static SQLExceptionCode fromErrorCode(int errorCode) throws 
SQLException {
+    public static SQLExceptionCode fromErrorCode(int errorCode) {
         SQLExceptionCode code = errorCodeMap.get(errorCode);
         if (code == null) {
-            throw new 
SQLExceptionInfo.Builder(SQLExceptionCode.UNKNOWN_ERROR_CODE)
-            .setMessage(Integer.toString(errorCode)).build().buildException();
+            return SQLExceptionCode.UNKNOWN_ERROR_CODE;
         }
         return code;
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/519f9e05/phoenix-core/src/main/java/org/apache/phoenix/util/ServerUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/ServerUtil.java 
b/phoenix-core/src/main/java/org/apache/phoenix/util/ServerUtil.java
index 0998e72..a51dc84 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/ServerUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/ServerUtil.java
@@ -116,21 +116,16 @@ public class ServerUtil {
     }
 
     private static SQLException parseRemoteException(Throwable t) {
-               String message = t.getLocalizedMessage();
-               if (message != null) {
+        String message = t.getLocalizedMessage();
+        if (message != null) {
             // If the message matches the standard pattern, recover the 
SQLException and throw it.
             Matcher matcher = PATTERN.matcher(t.getLocalizedMessage());
             if (matcher.find()) {
                 int statusCode = Integer.parseInt(matcher.group(1));
-                SQLExceptionCode code;
-                try {
-                    code = SQLExceptionCode.fromErrorCode(statusCode);
-                } catch (SQLException e) {
-                    return e;
-                }
-                return new 
SQLExceptionInfo.Builder(code).setMessage(matcher.group()).build().buildException();
+                SQLExceptionCode code = 
SQLExceptionCode.fromErrorCode(statusCode);
+                return new 
SQLExceptionInfo.Builder(code).setMessage(matcher.group()).setRootCause(t).build().buildException();
             }
-               }
+        }
         return null;
     }
 

Reply via email to