juliuszsompolski commented on code in PR #54007:
URL: https://github.com/apache/spark/pull/54007#discussion_r2735919383
##########
core/src/main/scala/org/apache/spark/util/Utils.scala:
##########
@@ -1424,32 +1437,30 @@ private[spark] object Utils
* below the original doTryWithCallerStacktrace which triggered it, with the
caller stack trace
* of the current caller of getTryWithCallerStacktrace.
*
- * Full stack trace of the original doTryWithCallerStacktrace caller can be
retrieved with
- * ```
- * ex.getSuppressed.find { e =>
- * e.isInstanceOf[Utils.OriginalTryStackTraceException]
- * }
- * ```
- *
+ * On subsequent accesses (not the first), the original stacktrace is added
as a suppressed
+ * exception to help with debugging.
*
* @param t Try from doTryWithCallerStacktrace
+ * @param isFirstAccess Whether this is the first access to the Try value
* @return Result of the Try or rethrows the failure exception with modified
stacktrace.
*/
- def getTryWithCallerStacktrace[T](t: Try[T]): T = t match {
+ def getTryWithCallerStacktrace[T](t: Try[T], isFirstAccess: Boolean = true):
T = t match {
+ case Failure(wrapper: TryStackTraceWrapper) =>
+ val originalEx = wrapper.originalException
+ // Stitch the stacktrace: keep the "below" part, replace "above" with
current caller
+ originalEx.setStackTrace(
+ wrapper.belowStacktrace ++
Thread.currentThread().getStackTrace.drop(1))
+ // On subsequent accesses, add suppressed exception showing original
stacktrace
+ if (!isFirstAccess) {
+ val alreadyAdded = originalEx.getSuppressed.exists(
+ _.isInstanceOf[OriginalTryStackTraceException])
+ if (!alreadyAdded) {
+ originalEx.addSuppressed(wrapper.originalStacktraceEx)
+ }
+ }
+ throw originalEx
case Failure(ex) =>
- val originalStacktraceEx = ex.getSuppressed.find { e =>
- // added in doTryWithCallerStacktrace
- e.isInstanceOf[OriginalTryStackTraceException]
- }.getOrElse {
- // If we don't have the expected stacktrace information, just rethrow
- throw ex
- }.asInstanceOf[OriginalTryStackTraceException]
- val belowStacktrace = originalStacktraceEx.getStackTrace
- .take(originalStacktraceEx.doTryWithCallerStacktraceDepth)
- // We are modifying and throwing the original exception. It would be
better if we could
- // return a copy, but we can't easily clone it and preserve. If this is
accessed from
- // multiple threads that then look at the stack trace, this could break.
Review Comment:
I would preserve this code comment next to stack stitching because it still
applies.
--
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]