heyihong commented on code in PR #42377:
URL: https://github.com/apache/spark/pull/42377#discussion_r1329349965


##########
connector/connect/common/src/main/scala/org/apache/spark/sql/connect/client/GrpcExceptionConverter.scala:
##########
@@ -93,33 +177,44 @@ private[client] object GrpcExceptionConverter extends 
JsonUtils {
       new SparkArrayIndexOutOfBoundsException(message)),
     errorConstructor[DateTimeException]((message, _) => new 
SparkDateTimeException(message)),
     errorConstructor((message, cause) => new SparkRuntimeException(message, 
cause)),
-    errorConstructor((message, cause) => new SparkUpgradeException(message, 
cause)))
+    errorConstructor((message, cause) => new SparkUpgradeException(message, 
cause)),
+    errorConstructor((message, cause) => new SparkException(message, 
cause.orNull)))
 
-  private def errorInfoToThrowable(info: ErrorInfo, message: String): 
Option[Throwable] = {
-    val classes =
-      mapper.readValue(info.getMetadataOrDefault("classes", "[]"), 
classOf[Array[String]])
+  private def exceptionInfoToThrowable(exceptionInfo: ExceptionInfo): 
Option[Throwable] = {
+    val classHierarchy = exceptionInfo.getErrorTypeHierarchyList.asScala
 
-    classes
-      .find(errorFactory.contains)
-      .map { cls =>
-        val constructor = errorFactory.get(cls).get
-        constructor(message, None)
-      }
-  }
-
-  private def toThrowable(ex: StatusRuntimeException): Throwable = {
-    val status = StatusProto.fromThrowable(ex)
-
-    val fallbackEx = new SparkException(ex.toString, ex.getCause)
+    if (classHierarchy.isEmpty) {
+      return None
+    }
 
-    val errorInfoOpt = status.getDetailsList.asScala
-      .find(_.is(classOf[ErrorInfo]))
+    val constructor =
+      classHierarchy
+        .flatMap(errorFactory.get)
+        .headOption
+        .getOrElse((message: String, cause: Option[Throwable]) =>
+          new SparkException(
+            s"Exception in server ${classHierarchy.head}: ${message}",
+            cause.orNull))
+
+    val causeOpt = if (exceptionInfo.hasCause) {
+      exceptionInfoToThrowable(exceptionInfo.getCause)
+    } else {
+      None
+    }

Review Comment:
   It fallbacks to the abbreviated FetchErrorDetailsResponse. 
   
   ```
     for (enrichErrorEnabled <- Seq(false, true)) {
       test(s"throw SparkException with large cause exception - 
$enrichErrorEnabled") {
         withSQLConf("spark.sql.connect.enrichError.enabled" -> 
enrichErrorEnabled.toString) {
           val session = spark
           import session.implicits._
   
           val throwException =
             udf((_: String) => throw new SparkException("test" * 10000))
   
           val ex = intercept[SparkException] {
             Seq("1").toDS.withColumn("udf_val", 
throwException($"value")).collect()
           }
   
           assert(ex.getCause.isInstanceOf[SparkException])
           if (enrichErrorEnabled) {
             assert(ex.getCause.getMessage.contains("test" * 10000))
           } else {
             assert(ex.getCause.getMessage.startsWith("test"))
           }
         }
       }
     }
   ```



-- 
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