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


##########
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)
+      }
   }
-}
 
+  private def toThrowable(ex: StatusRuntimeException): Throwable = {
+    val status = StatusProto.fromThrowable(ex)
 
+    status
+      .getDetailsList
+      .asScala
+      .find(_.is(classOf[ErrorInfo]))
+      .flatMap { d =>

Review Comment:
   I would cut this monadic chaining (see also 
https://github.com/databricks/scala-style-guide#chaining).



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