HyukjinKwon commented on code in PR #42266:
URL: https://github.com/apache/spark/pull/42266#discussion_r1285762484


##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/connect/client/GrpcExceptionConverter.scala:
##########
@@ -53,11 +60,33 @@ private[client] object GrpcExceptionConverter {
     }
   }
 
-  private def toSparkThrowable(ex: StatusRuntimeException): SparkThrowable 
with Throwable = {
-    val status = StatusProto.fromThrowable(ex)
-    // TODO: Add finer grained error conversion
-    new SparkException(status.getMessage, ex.getCause)
+  private val errorFactory = new ErrorFactoryBuilder()
+    .registerConstructor((message, _) => new ParseException(None, message, 
Origin(), Origin()))
+    .registerConstructor((message, _) => new AnalysisException(message))
+    .build()
+
+  private def errorInfoToThrowable(info: ErrorInfo, message: String): 
Option[Throwable] = {
+    val classes =
+      mapper.readValue(info.getMetadataOrDefault("classes", "[]"), 
classOf[Array[String]])
+
+    classes
+      .find(errorFactory.contains(_))
+      .map { cls =>
+        errorFactory.get(cls).get(message, null)

Review Comment:
   hm, I think this results in `Some(null)` instead of `None`, and later it 
will cause NPE I believe?



##########
connector/connect/client/jvm/src/main/scala/org/apache/spark/sql/connect/client/GrpcExceptionConverter.scala:
##########
@@ -53,11 +60,33 @@ private[client] object GrpcExceptionConverter {
     }
   }
 
-  private def toSparkThrowable(ex: StatusRuntimeException): SparkThrowable 
with Throwable = {
-    val status = StatusProto.fromThrowable(ex)
-    // TODO: Add finer grained error conversion
-    new SparkException(status.getMessage, ex.getCause)
+  private val errorFactory = new ErrorFactoryBuilder()
+    .registerConstructor((message, _) => new ParseException(None, message, 
Origin(), Origin()))
+    .registerConstructor((message, _) => new AnalysisException(message))
+    .build()
+
+  private def errorInfoToThrowable(info: ErrorInfo, message: String): 
Option[Throwable] = {
+    val classes =
+      mapper.readValue(info.getMetadataOrDefault("classes", "[]"), 
classOf[Array[String]])
+
+    classes
+      .find(errorFactory.contains(_))

Review Comment:
   ```suggestion
         .find(errorFactory.contains)
   ```



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