hvanhovell commented on code in PR #42377:
URL: https://github.com/apache/spark/pull/42377#discussion_r1309579141
##########
connector/connect/common/src/main/scala/org/apache/spark/sql/connect/client/GrpcExceptionConverter.scala:
##########
@@ -90,33 +183,38 @@ 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)))
-
- 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 =>
- val constructor = errorFactory.get(cls).get
- constructor(message, None)
- }
- }
-
- private def toThrowable(ex: StatusRuntimeException): Throwable = {
- val status = StatusProto.fromThrowable(ex)
-
- val fallbackEx = new SparkException(status.getMessage, ex.getCause)
-
- val errorInfoOpt = status.getDetailsList.asScala
- .find(_.is(classOf[ErrorInfo]))
-
- if (errorInfoOpt.isEmpty) {
- return fallbackEx
+ errorConstructor((message, cause) => new SparkUpgradeException(message,
cause)),
+ errorConstructor((message, cause) => new SparkException(message,
cause.orNull)))
+
+ private case class Error(
+ errorId: String,
+ classes: Array[String],
+ message: String,
+ stackTraceOpt: Option[Array[StackTraceElement]])
+
+ private def errorsToThrowable(errors: Array[Error]): Option[Throwable] = {
+ if (errors.isEmpty) {
+ return None
+ }
+ if (errors.head.classes.isEmpty) {
+ return None
}
+ val constructor =
+ errors.head.classes
+ .find(errorFactory.contains)
Review Comment:
this would save a map lookup:
`errors.head.classes.iterator.flatmap(errorFactory.get).headOption.getOrElse(...)`
--
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]