Skip to content

Commit

Permalink
[Gradle, JS] Useful message on exception for webpack
Browse files Browse the repository at this point in the history
#KT-38286 fixed
  • Loading branch information
ilgonmic committed Apr 16, 2020
1 parent f8c44be commit fa4003b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,22 @@ internal fun Project.execWithErrorLogger(description: String, body: (ExecAction)
body(exec)
return project!!.operation(description) {
progress(description)
val client = TeamCityMessageCommonClient(logger, this)
exec.standardOutput = TCServiceMessageOutputStreamHandler(
client = TeamCityMessageCommonClient(logger, this),
client = client,
onException = { },
logger = logger
)
exec.errorOutput = TCServiceMessageOutputStreamHandler(
client = TeamCityMessageCommonClient(logger, this),
client = client,
onException = { },
logger = logger
)
exec.isIgnoreExitValue = true
val result = exec.execute()
if (result.exitValue != 0) {
error(
"""
Process '$description' returns ${result.exitValue}
""".trimIndent()
client.testFailedMessage()
)
}
result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ import jetbrains.buildServer.messages.serviceMessages.ServiceMessage
import jetbrains.buildServer.messages.serviceMessages.ServiceMessageParserCallback
import org.gradle.api.logging.Logger
import org.gradle.internal.logging.progress.ProgressLogger
import org.jetbrains.kotlin.gradle.utils.clearAnsiColor
import java.text.ParseException

class TeamCityMessageCommonClient(
private val log: Logger,
private val progressLogger: ProgressLogger
) : ServiceMessageParserCallback {

private val errors = mutableListOf<String>()

private val stackTraceProcessor = TeamCityMessageStackTraceProcessor()

override fun parseException(e: ParseException, text: String) {
Expand All @@ -29,6 +32,11 @@ class TeamCityMessageCommonClient(
}
}

internal fun testFailedMessage(): String {
return errors
.joinToString("\n")
}

private fun printMessage(text: String, type: String?) {
val value = text.trimEnd()
progressLogger.progress(value)
Expand All @@ -41,6 +49,10 @@ class TeamCityMessageCommonClient(
}
}

when (actualType) {
ERROR, WARN -> errors.add(value.clearAnsiColor())
}

actualType?.let { log.processLogMessage(value, it) }
}

Expand Down

0 comments on commit fa4003b

Please sign in to comment.