From dfa9f03676242a32eb3a7e8b16edf6b577b2934a Mon Sep 17 00:00:00 2001 From: Piotr Chabelski Date: Tue, 3 Dec 2024 23:32:14 +0100 Subject: [PATCH] Make `generate-junit-reports.sc` script recover from test failures containing no trace data (#3341) --- .github/scripts/generate-junit-reports.sc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/scripts/generate-junit-reports.sc b/.github/scripts/generate-junit-reports.sc index 5d47325a3b..3a41bd2119 100755 --- a/.github/scripts/generate-junit-reports.sc +++ b/.github/scripts/generate-junit-reports.sc @@ -7,6 +7,7 @@ import java.io.File import scala.collection.mutable.ArrayBuffer import scala.annotation.tailrec import java.nio.file.Paths +import scala.util.Try case class Trace(declaringClass: String, methodName: String, fileName: String, lineNumber: Int) { override def toString: String = s"$declaringClass.$methodName($fileName:$lineNumber)" @@ -97,11 +98,14 @@ val suites = tests.groupBy(_.fullyQualifiedName).map { case (suit, tests) => } time={test.duration.toString}> { test.failure.map { failure => + val maybeTrace = Try(failure.trace(1)).toOption + val fileName = maybeTrace.map(_.fileName).getOrElse("unknown") + val lineNumber = maybeTrace.map(_.lineNumber).getOrElse(-1) ERROR: {failure.message} Category: {failure.name} - File: {failure.trace(1).fileName} - Line: {failure.trace(1).lineNumber} + File: {fileName} + Line: {lineNumber} }.orNull }