allisonwang-db commented on code in PR #40575:
URL: https://github.com/apache/spark/pull/40575#discussion_r1154490873


##########
connector/connect/server/src/main/scala/org/apache/spark/sql/connect/service/SparkConnectService.scala:
##########
@@ -73,18 +74,26 @@ class SparkConnectService(debug: Boolean)
     classes.toSeq
   }
 
-  private def buildStatusFromThrowable(st: Throwable): RPCStatus = {
+  private def buildStatusFromThrowable(
+      st: Throwable,
+      stackTraceEnabled: Boolean = false): RPCStatus = {
+    val errorInfo = ErrorInfo
+      .newBuilder()
+      .setReason(st.getClass.getName)
+      .setDomain("org.apache.spark")
+      .putMetadata("classes", 
compact(render(allClasses(st.getClass).map(_.getName))))
+
+    val withStackTrace = if (stackTraceEnabled) {
+      val stackTrace = ExceptionUtils.getStackTrace(st)
+      errorInfo.putMetadata("stackTrace", StringUtils.abbreviate(stackTrace, 
4096))

Review Comment:
   This is a good question. I wonder if we should make this configurable for 
users.



##########
connector/connect/server/src/main/scala/org/apache/spark/sql/connect/service/SparkConnectService.scala:
##########
@@ -73,18 +74,26 @@ class SparkConnectService(debug: Boolean)
     classes.toSeq
   }
 
-  private def buildStatusFromThrowable(st: Throwable): RPCStatus = {
+  private def buildStatusFromThrowable(
+      st: Throwable,
+      stackTraceEnabled: Boolean = false): RPCStatus = {
+    val errorInfo = ErrorInfo
+      .newBuilder()
+      .setReason(st.getClass.getName)
+      .setDomain("org.apache.spark")
+      .putMetadata("classes", 
compact(render(allClasses(st.getClass).map(_.getName))))
+
+    val withStackTrace = if (stackTraceEnabled) {
+      val stackTrace = ExceptionUtils.getStackTrace(st)
+      errorInfo.putMetadata("stackTrace", StringUtils.abbreviate(stackTrace, 
4096))
+    } else {
+      errorInfo
+    }
+
     RPCStatus
       .newBuilder()
       .setCode(RPCCode.INTERNAL_VALUE)
-      .addDetails(
-        ProtoAny.pack(
-          ErrorInfo
-            .newBuilder()
-            .setReason(st.getClass.getName)
-            .setDomain("org.apache.spark")
-            .putMetadata("classes", 
compact(render(allClasses(st.getClass).map(_.getName))))
-            .build()))
+      .addDetails(ProtoAny.pack(withStackTrace.build()))

Review Comment:
   The stack trace is disabled by default, so it should not affect typical 
users. But I agree it can be hard to debug such issues. One solution could be 
to make the stack trace size configurable. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to