Skip to content

Commit

Permalink
[Gradle, JS] Stack trace processor
Browse files Browse the repository at this point in the history
#KT-38109 fixed
#KT-38286 fixed
  • Loading branch information
ilgonmic committed Apr 16, 2020
1 parent 3c033c1 commit 480a9c1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/

package org.jetbrains.kotlin.gradle.targets.js

internal class TeamCityMessageStackTraceProcessor {
private var firstLine: String? = null

fun process(text: String, firstLineAction: (String?) -> Unit) {
firstLine = if (text.trim().startsWith("at ")) {
firstLineAction(firstLine)
null
} else {
text
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) :

private val failedBrowsers: MutableList<String> = mutableListOf()

private var previousLine: String = ""
private var stackTraceProcessor = TeamCityMessageStackTraceProcessor()

override fun printNonTestOutput(text: String, type: String?) {
val value = text.trimEnd()
Expand All @@ -436,19 +436,16 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) :

private fun parseConsole(text: String, type: String?) {

val actualType = if (text.trim().startsWith("at ")) {
parseConsole(previousLine, ERROR)
previousLine = ""
ERROR
} else {
previousLine = text
type
var actualType = type
stackTraceProcessor.process(text) { line ->
actualType = ERROR
line?.let { parseConsole(it, actualType) }
}

val launcherMessage = KARMA_LAUNCHER_MESSAGE.matchEntire(text)
val launcherMessage = KARMA_MESSAGE.matchEntire(text)

val actualText = if (launcherMessage != null) {
val (message) = launcherMessage.destructured
val (_, message) = launcherMessage.destructured
when (actualType?.toLowerCase()) {
WARN, ERROR -> {
processFailedBrowsers(text)
Expand Down Expand Up @@ -542,5 +539,5 @@ class KotlinKarma(override val compilation: KotlinJsCompilation) :
}
}

private val KARMA_LAUNCHER_MESSAGE = "^.*\\[launcher]: ([\\w\\W]*)\$"
private val KARMA_MESSAGE = "^.*\\d{2} \\d{2} \\d{4,} \\d{2}:\\d{2}:\\d{2}.\\d{3}:(ERROR|WARN|INFO|DEBUG|LOG) \\[.*]: ([\\w\\W]*)\$"
.toRegex()

0 comments on commit 480a9c1

Please sign in to comment.