Skip to content

Commit 176d1e3

Browse files
committed
Add comments to explain the stack trace difference
1 parent ca509d3 commit 176d1e3

File tree

4 files changed

+36
-36
lines changed

4 files changed

+36
-36
lines changed

core/src/main/scala/org/apache/spark/TaskEndReason.scala

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ case class FetchFailed(
8383
* :: DeveloperApi ::
8484
* Task failed due to a runtime exception. This is the most common failure case and also captures
8585
* user program exceptions.
86+
*
87+
* `stackTrace` contains the stack trace of the exception itself. It still exists for backward
88+
* compatibility. It's better that using `this(e: Throwable, metrics: Option[TaskMetrics])` to
89+
* create `ExceptionFailure` as it will handle the backward compatibility properly.
90+
*
91+
* `fullStackTrace` is a better representation of the stack trace because it contains the whole
92+
* stack trace including the exception and its causes
8693
*/
8794
@DeveloperApi
8895
case class ExceptionFailure(
@@ -101,10 +108,23 @@ case class ExceptionFailure(
101108
if (fullStackTrace == null) {
102109
// fullStackTrace is added in 1.2.0
103110
// If fullStackTrace is null, use the old error string for backward compatibility
104-
Utils.exceptionString(className, description, stackTrace)
111+
exceptionString(className, description, stackTrace)
105112
} else {
106113
fullStackTrace
107114
}
115+
116+
/**
117+
* Return a nice string representation of the exception, including the stack trace.
118+
* Note: It does not include the exception's causes, and is only used for backward compatibility.
119+
*/
120+
private def exceptionString(
121+
className: String,
122+
description: String,
123+
stackTrace: Array[StackTraceElement]): String = {
124+
val desc = if (description == null) "" else description
125+
val st = if (stackTrace == null) "" else stackTrace.map(" " + _).mkString("\n")
126+
s"$className: $desc\n$st"
127+
}
108128
}
109129

110130
/**

core/src/main/scala/org/apache/spark/shuffle/FetchFailedException.scala

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,9 @@ private[spark] class FetchFailedException(
3333
mapId: Int,
3434
reduceId: Int,
3535
message: String,
36-
cause: Throwable)
36+
cause: Throwable = null)
3737
extends Exception(message, cause) {
3838

39-
def this(
40-
bmAddress: BlockManagerId,
41-
shuffleId: Int,
42-
mapId: Int,
43-
reduceId: Int,
44-
message: String) {
45-
this(bmAddress, shuffleId, mapId, reduceId, message, null)
46-
}
47-
4839
def this(
4940
bmAddress: BlockManagerId,
5041
shuffleId: Int,

core/src/main/scala/org/apache/spark/ui/jobs/StageTable.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,15 @@ private[ui] class FailedStageTable(
207207
failureReason
208208
})
209209
val details = if (isMultiline) {
210-
// scalastyle:off
211-
<span onclick="this.parentNode.querySelector('.stacktrace-details').classList.toggle('collapsed')"
212-
class="expand-details">
213-
+details
214-
</span> ++
215-
<div class="stacktrace-details collapsed">
216-
<pre>{failureReason}</pre>
217-
</div>
218-
// scalastyle:on
210+
// scalastyle:off
211+
<span onclick="this.parentNode.querySelector('.stacktrace-details').classList.toggle('collapsed')"
212+
class="expand-details">
213+
+details
214+
</span> ++
215+
<div class="stacktrace-details collapsed">
216+
<pre>{failureReason}</pre>
217+
</div>
218+
// scalastyle:on
219219
} else {
220220
""
221221
}

core/src/main/scala/org/apache/spark/util/Utils.scala

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,32 +1596,21 @@ private[spark] object Utils extends Logging {
15961596
.orNull
15971597
}
15981598

1599-
/** Return a nice string representation of the exception, including the stack trace. */
1599+
/**
1600+
* Return a nice string representation of the exception. It will call "printStackTrace" to
1601+
* recursively generate the stack trace including the exception and its causes.
1602+
*/
16001603
def exceptionString(e: Throwable): String = {
16011604
if (e == null) {
16021605
""
16031606
} else {
1607+
// Use e.printStackTrace here because e.getStackTrace doesn't include the cause
16041608
val stringWriter = new StringWriter()
16051609
e.printStackTrace(new PrintWriter(stringWriter))
16061610
stringWriter.toString
16071611
}
16081612
}
16091613

1610-
/**
1611-
* Return a nice string representation of the exception, including the stack trace.
1612-
* It's only used for backward compatibility.
1613-
* Note: deprecated because it does not include the exception's cause.
1614-
*/
1615-
@deprecated("Use exceptionString(Throwable) instead", "1.2.0")
1616-
def exceptionString(
1617-
className: String,
1618-
description: String,
1619-
stackTrace: Array[StackTraceElement]): String = {
1620-
val desc = if (description == null) "" else description
1621-
val st = if (stackTrace == null) "" else stackTrace.map(" " + _).mkString("\n")
1622-
s"$className: $desc\n$st"
1623-
}
1624-
16251614
/**
16261615
* Convert all spark properties set in the given SparkConf to a sequence of java options.
16271616
*/

0 commit comments

Comments
 (0)