MaxGekk commented on code in PR #37520:
URL: https://github.com/apache/spark/pull/37520#discussion_r947195431
##########
core/src/main/scala/org/apache/spark/SparkThrowableHelper.scala:
##########
@@ -135,4 +143,41 @@ 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 =>
+ val jValue = ("errorClass" -> "legacy") ~
+ ("messageParameters" -> JObject(List("message" ->
JString(e.getMessage)))) ~
+ ("queryContext" -> JArray(List.empty))
+ compact(render(jValue))
+ case MINIMAL | STANDARD =>
+ val errorClass = e.getErrorClass
+ val message = if (format == STANDARD) {
+ val errorInfo = errorClassToInfoMap.getOrElse(errorClass,
+ throw new IllegalArgumentException(s"Cannot find error class
'$errorClass'"))
+ Some(errorInfo.messageFormat)
+ } else None
+ assert(e.getParameterNames.size == e.getMessageParameters.size,
+ "Number of message parameter names and values must be the same")
+ val jValue = ("errorClass" -> errorClass) ~
+ ("errorSubClass" -> Option(e.getErrorSubClass)) ~
+ ("message" -> message) ~
+ ("sqlState" -> Option(e.getSqlState)) ~
+ ("messageParameters" ->
+ JObject((e.getParameterNames zip
e.getMessageParameters.map(JString)).toList)) ~
+ ("queryContext" -> JArray(
+ e.getQueryContext.map(c => JObject(
+ "objectType" -> JString(c.objectType()),
+ "objectName" -> JString(c.objectName()),
+ "startIndex" -> JInt(c.startIndex()),
+ "stopIndex" -> JInt(c.stopIndex()),
+ "fragment" -> JString(c.fragment()))).toList)
+ )
+ val rendered = render(jValue)
+ if (format == MINIMAL) compact(rendered) else pretty(rendered)
Review Comment:
@srielau Should we output MINIMAL in the compact or pretty form?
--
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]