cloud-fan commented on code in PR #37520:
URL: https://github.com/apache/spark/pull/37520#discussion_r947677976


##########
core/src/main/scala/org/apache/spark/SparkThrowableHelper.scala:
##########
@@ -135,4 +140,59 @@ private[spark] object SparkThrowableHelper {
   def isInternalError(errorClass: String): Boolean = {
     errorClass == "INTERNAL_ERROR"
   }
+
+  def getMessage(e: SparkThrowable with Throwable, format: 
ErrorMessageFormat.Value): String = {
+    import ErrorMessageFormat._
+    format match {
+      case PRETTY => e.getMessage
+      case MINIMAL | STANDARD if e.getErrorClass == null =>
+        toJsonString { g =>
+          g.writeStartObject()
+          g.writeStringField("errorClass", "legacy")
+          g.writeObjectFieldStart("messageParameters")
+          g.writeStringField("message", e.getMessage)
+          g.writeEndObject()
+          g.writeArrayFieldStart("queryContext")
+          g.writeEndArray()
+          g.writeEndObject()
+        }
+      case MINIMAL | STANDARD =>
+        val errorClass = e.getErrorClass
+        assert(e.getParameterNames.size == e.getMessageParameters.size,
+          "Number of message parameter names and values must be the same")
+        toJsonString { generator =>
+          val g = if (format == STANDARD) generator.useDefaultPrettyPrinter() 
else generator
+          g.writeStartObject()
+          g.writeStringField("errorClass", errorClass)
+          val errorSubClass = e.getErrorSubClass
+          if (errorSubClass != null) g.writeStringField("errorSubClass", 
errorSubClass)
+          if (format == STANDARD) {
+            val errorInfo = errorClassToInfoMap.getOrElse(errorClass,
+              throw SparkException.internalError(s"Cannot find the error class 
'$errorClass'"))
+            g.writeStringField("message", errorInfo.messageFormat)
+          }
+          val sqlState = e.getSqlState
+          if (sqlState != null) g.writeStringField("sqlState", sqlState)
+          g.writeObjectFieldStart("messageParameters")
+          (e.getParameterNames zip e.getMessageParameters).foreach { case 
(name, value) =>
+            g.writeStringField(name, value)
+          }
+          g.writeEndObject()
+          g.writeArrayFieldStart("queryContext")
+          e.getQueryContext.map { c =>
+            g.writeStartObject()
+            g.writeStringField("objectType", c.objectType())
+            g.writeStringField("objectName", c.objectName())
+            val startIndex = c.startIndex() + 1

Review Comment:
   does this mean it's inconsistent with the original text error message? cc 
@gengliangwang 



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