asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mb...@apache.org
Subject asterixdb git commit: Do not include Exception class in error message
Date Fri, 19 May 2017 00:13:57 GMT
Repository: asterixdb
Updated Branches:
  refs/heads/master c411db754 -> 34fc9ef89


Do not include Exception class in error message

Change-Id: I33c76222dabfe6ede67dbcd7f0992cbb047265ef
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1757
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
BAD: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Michael Blow <mblow@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/34fc9ef8
Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/34fc9ef8
Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/34fc9ef8

Branch: refs/heads/master
Commit: 34fc9ef89967fdccdda8d31d571b0f26ae39f569
Parents: c411db7
Author: Till Westmann <tillw@apache.org>
Authored: Thu May 18 13:58:29 2017 -0700
Committer: Michael Blow <mblow@apache.org>
Committed: Thu May 18 17:13:42 2017 -0700

----------------------------------------------------------------------
 .../api/http/server/QueryServiceServlet.java       | 13 ++++++++++---
 .../apache/asterix/api/http/server/ResultUtil.java | 15 +++++++++------
 .../message/ExecuteStatementRequestMessage.java    | 17 ++++++++---------
 3 files changed, 27 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/34fc9ef8/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
index c45f24a..479c8b0 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
@@ -48,7 +48,9 @@ import org.apache.asterix.translator.IStatementExecutorContext;
 import org.apache.asterix.translator.IStatementExecutorFactory;
 import org.apache.asterix.translator.SessionConfig;
 import org.apache.asterix.translator.SessionOutput;
+import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.api.application.IServiceContext;
+import org.apache.hyracks.api.exceptions.HyracksException;
 import org.apache.hyracks.http.api.IServletRequest;
 import org.apache.hyracks.http.api.IServletResponse;
 import org.apache.hyracks.http.server.utils.HttpUtil;
@@ -415,13 +417,18 @@ public class QueryServiceServlet extends AbstractQueryApiServlet {
             if (ResultDelivery.IMMEDIATE == delivery || ResultDelivery.DEFERRED == delivery)
{
                 ResultUtil.printStatus(sessionOutput, ResultStatus.SUCCESS);
             }
-        } catch (AsterixException | TokenMgrError | org.apache.asterix.aqlplus.parser.TokenMgrError
pe) {
-            GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, pe.getMessage(), pe);
+        } catch (AlgebricksException | TokenMgrError | org.apache.asterix.aqlplus.parser.TokenMgrError
pe) {
+            GlobalConfig.ASTERIX_LOGGER.log(Level.INFO, pe.getMessage(), pe);
             ResultUtil.printError(resultWriter, pe);
             ResultUtil.printStatus(sessionOutput, ResultStatus.FATAL);
             status = HttpResponseStatus.BAD_REQUEST;
+        } catch (HyracksException pe) {
+            GlobalConfig.ASTERIX_LOGGER.log(Level.WARNING, pe.getMessage(), pe);
+            ResultUtil.printError(resultWriter, pe);
+            ResultUtil.printStatus(sessionOutput, ResultStatus.FATAL);
+            status = HttpResponseStatus.INTERNAL_SERVER_ERROR;
         } catch (Exception e) {
-            GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, e.toString(), e);
+            GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, "Unexpected exception", e);
             ResultUtil.printError(resultWriter, e);
             ResultUtil.printStatus(sessionOutput, ResultStatus.FATAL);
             status = HttpResponseStatus.INTERNAL_SERVER_ERROR;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/34fc9ef8/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ResultUtil.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ResultUtil.java
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ResultUtil.java
index 3bcd670..f004446 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ResultUtil.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ResultUtil.java
@@ -37,6 +37,7 @@ import org.apache.asterix.app.result.ResultHandle;
 import org.apache.asterix.app.result.ResultPrinter;
 import org.apache.asterix.app.result.ResultReader;
 import org.apache.asterix.common.api.IApplicationContext;
+import org.apache.asterix.lang.aql.parser.TokenMgrError;
 import org.apache.asterix.om.types.ARecordType;
 import org.apache.asterix.translator.IStatementExecutor.Stats;
 import org.apache.asterix.translator.SessionOutput;
@@ -44,6 +45,7 @@ import org.apache.http.ParseException;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.core.algebra.prettyprint.AlgebricksAppendable;
 import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.api.exceptions.HyracksException;
 import org.apache.hyracks.util.JSONUtil;
 import org.apache.log4j.Logger;
 
@@ -115,17 +117,18 @@ public class ResultUtil {
 
     public static void printError(PrintWriter pw, Throwable e, boolean comma) {
         Throwable rootCause = getRootCause(e);
-        if (rootCause == null) {
-            rootCause = e;
-        }
         final boolean addStack = false;
         pw.print("\t\"");
         pw.print(AbstractQueryApiServlet.ResultFields.ERRORS.str());
         pw.print("\": [{ \n");
         printField(pw, QueryServiceServlet.ErrorField.CODE.str(), "1");
-        final String msg = rootCause.getMessage();
-        printField(pw, QueryServiceServlet.ErrorField.MSG.str(),
-                JSONUtil.escape(msg != null ? msg : rootCause.getClass().getSimpleName()),
addStack);
+        String msg = rootCause.getMessage();
+        if (!(rootCause instanceof AlgebricksException || rootCause instanceof HyracksException
+                || rootCause instanceof TokenMgrError
+                || rootCause instanceof org.apache.asterix.aqlplus.parser.TokenMgrError))
{
+            msg = rootCause.getClass().getSimpleName() + (msg == null ? "" : ": " + msg);
+        }
+        printField(pw, QueryServiceServlet.ErrorField.MSG.str(), JSONUtil.escape(msg), addStack);
         pw.print(comma ? "\t}],\n" : "\t}]\n");
     }
 

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/34fc9ef8/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/message/ExecuteStatementRequestMessage.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/message/ExecuteStatementRequestMessage.java
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/message/ExecuteStatementRequestMessage.java
index defa180..fc0c1ff 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/message/ExecuteStatementRequestMessage.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/message/ExecuteStatementRequestMessage.java
@@ -32,7 +32,6 @@ import org.apache.asterix.common.api.IClusterManagementWork;
 import org.apache.asterix.common.config.GlobalConfig;
 import org.apache.asterix.common.context.IStorageComponentProvider;
 import org.apache.asterix.common.dataflow.ICcApplicationContext;
-import org.apache.asterix.common.exceptions.AsterixException;
 import org.apache.asterix.common.messaging.api.ICcAddressedMessage;
 import org.apache.asterix.compiler.provider.ILangCompilationProvider;
 import org.apache.asterix.hyracks.bootstrap.CCApplication;
@@ -47,8 +46,10 @@ import org.apache.asterix.translator.IStatementExecutorContext;
 import org.apache.asterix.translator.IStatementExecutorFactory;
 import org.apache.asterix.translator.SessionConfig;
 import org.apache.asterix.translator.SessionOutput;
+import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.api.application.ICCServiceContext;
 import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.api.exceptions.HyracksException;
 import org.apache.hyracks.control.cc.ClusterControllerService;
 
 public final class ExecuteStatementRequestMessage implements ICcAddressedMessage {
@@ -129,16 +130,14 @@ public final class ExecuteStatementRequestMessage implements ICcAddressedMessage
                 outPrinter.close();
                 responseMsg.setResult(outWriter.toString());
                 responseMsg.setMetadata(outMetadata);
-            } catch (TokenMgrError | org.apache.asterix.aqlplus.parser.TokenMgrError pe)
{
-                GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, pe.getMessage(), pe);
+            } catch (AlgebricksException | HyracksException | TokenMgrError
+                    | org.apache.asterix.aqlplus.parser.TokenMgrError pe) {
+                // we trust that "our" exceptions are serializable and have a comprehensible
error message
+                GlobalConfig.ASTERIX_LOGGER.log(Level.WARNING, pe.getMessage(), pe);
                 responseMsg.setError(pe);
-            } catch (AsterixException pe) {
-                GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, pe.getMessage(), pe);
-                responseMsg.setError(new AsterixException(pe.getMessage()));
             } catch (Exception e) {
-                String estr = e.toString();
-                GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, estr, e);
-                responseMsg.setError(new Exception(estr));
+                GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, "Unexpected exception", e);
+                responseMsg.setError(new Exception(e.toString()));
             }
 
             try {


Mime
View raw message