From 0ea4a14fcd77a954898f58b4a624d0d515b52eda Mon Sep 17 00:00:00 2001 From: weiwenda Date: Sun, 29 Sep 2019 16:19:41 +0800 Subject: [PATCH] [LIVY-688] Error message of BypassJobStatus should contains cause information of Exception ## What changes were proposed in this pull request? Change the implement of org.apache.livy.rsc.Utils.stackTraceAsString to guava Throwables.getStackTraceAsString, so that user can receive details of error message by calling org.apache.livy.client.http.JobHandleImpl.get. https://issues.apache.org/jira/browse/LIVY-688 Author: weiwenda Closes #237 from WeiWenda/livy-err-clear. --- rsc/src/main/java/org/apache/livy/rsc/Utils.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/rsc/src/main/java/org/apache/livy/rsc/Utils.java b/rsc/src/main/java/org/apache/livy/rsc/Utils.java index d2c005975..3c8a5e664 100644 --- a/rsc/src/main/java/org/apache/livy/rsc/Utils.java +++ b/rsc/src/main/java/org/apache/livy/rsc/Utils.java @@ -17,6 +17,8 @@ package org.apache.livy.rsc; +import java.io.PrintWriter; +import java.io.StringWriter; import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicInteger; @@ -91,13 +93,9 @@ public static String join(Iterable strs, String sep) { } public static String stackTraceAsString(Throwable t) { - StringBuilder sb = new StringBuilder(); - sb.append(t.getClass().getName()).append(": ").append(t.getMessage()); - for (StackTraceElement e : t.getStackTrace()) { - sb.append("\n"); - sb.append(e.toString()); - } - return sb.toString(); + StringWriter stringWriter = new StringWriter(); + t.printStackTrace(new PrintWriter(stringWriter)); + return stringWriter.toString(); } public static void addListener(Future future, final FutureListener lsnr) {