You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/05/19 12:50:59 UTC

[GitHub] [spark] gengliangwang commented on a diff in pull request #36612: [SPARK-39234][SQL] Code clean up in SparkThrowableHelper.getMessage

gengliangwang commented on code in PR #36612:
URL: https://github.com/apache/spark/pull/36612#discussion_r877015458


##########
core/src/main/scala/org/apache/spark/ErrorInfo.scala:
##########
@@ -77,20 +77,25 @@ private[spark] object SparkThrowableHelper {
       queryContext: String = ""): String = {
     val errorInfo = errorClassToInfoMap.getOrElse(errorClass,
       throw new IllegalArgumentException(s"Cannot find error class '$errorClass'"))
-    if (errorInfo.subClass.isDefined) {
+    val (displayClass, displayMessageParameters, displayFormat) = if (errorInfo.subClass.isEmpty) {
+      (errorClass, messageParameters, errorInfo.messageFormat)
+    } else {
       val subClass = errorInfo.subClass.get
       val subErrorClass = messageParameters.head
       val errorSubInfo = subClass.getOrElse(subErrorClass,
         throw new IllegalArgumentException(s"Cannot find sub error class '$subErrorClass'"))
-      val subMessageParameters = messageParameters.tail
-      "[" + errorClass + "." + subErrorClass + "] " + String.format((errorInfo.messageFormat +
-        errorSubInfo.messageFormat).replaceAll("<[a-zA-Z0-9_-]+>", "%s"),
-        subMessageParameters: _*) + queryContext
+      (errorClass + "." + subErrorClass, messageParameters.tail,
+        errorInfo.messageFormat + errorSubInfo.messageFormat)
+    }
+    val displayMessage = String.format(
+      displayFormat.replaceAll("<[a-zA-Z0-9_-]+>", "%s"),

Review Comment:
   Here we avoid writing `.replaceAll("<[a-zA-Z0-9_-]+>", "%s")` twice 



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org