Log daemon exception for In process compilation into error.log

This commit is contained in:
nataliya.valtman
2022-09-29 13:28:33 +02:00
committed by Space Team
parent 242b83edbd
commit 2379185398
6 changed files with 22 additions and 11 deletions
@@ -40,19 +40,19 @@ fun launchProcessWithFallback(processBuilder: ProcessBuilder, reportingTargets:
NativePlatformLauncherWrapper().launch(processBuilder) NativePlatformLauncherWrapper().launch(processBuilder)
} }
catch (e: UnsatisfiedLinkError) { catch (e: UnsatisfiedLinkError) {
reportingTargets.report(DaemonReportCategory.DEBUG, "Could not start process with native process launcher, falling back to ProcessBuilder#start ($e)", reportingSource) reportingTargets.report(DaemonReportCategory.EXCEPTION, "Could not start process with native process launcher, falling back to ProcessBuilder#start ($e)", reportingSource)
null null
} }
catch (e: IOException) { catch (e: IOException) {
reportingTargets.report(DaemonReportCategory.DEBUG, "Could not start process with native process launcher, falling back to ProcessBuilder#start (${e.cause})", reportingSource) reportingTargets.report(DaemonReportCategory.EXCEPTION, "Could not start process with native process launcher, falling back to ProcessBuilder#start (${e.cause})", reportingSource)
null null
} }
catch (e: NoClassDefFoundError) { catch (e: NoClassDefFoundError) {
reportingTargets.report(DaemonReportCategory.DEBUG, "net.rubygrapefruit.platform library is not in the classpath, falling back to ProcessBuilder#start ($e)", reportingSource) reportingTargets.report(DaemonReportCategory.EXCEPTION, "net.rubygrapefruit.platform library is not in the classpath, falling back to ProcessBuilder#start ($e)", reportingSource)
null null
} }
catch (e: ClassNotFoundException) { catch (e: ClassNotFoundException) {
reportingTargets.report(DaemonReportCategory.DEBUG, "net.rubygrapefruit.platform library is not in the classpath, falling back to ProcessBuilder#start ($e)", reportingSource) reportingTargets.report(DaemonReportCategory.EXCEPTION, "net.rubygrapefruit.platform library is not in the classpath, falling back to ProcessBuilder#start ($e)", reportingSource)
null null
} }
?: processBuilder.start() ?: processBuilder.start()
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.incremental
import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.incremental.AbiSnapshotImpl.Companion.readAbiSnapshot import org.jetbrains.kotlin.incremental.AbiSnapshotImpl.Companion.readAbiSnapshot
import org.jetbrains.kotlin.incremental.AbiSnapshotImpl.Companion.writeAbiSnapshot import org.jetbrains.kotlin.incremental.AbiSnapshotImpl.Companion.writeAbiSnapshot
import org.jetbrains.kotlin.incremental.util.ExceptionLocation
import org.jetbrains.kotlin.incremental.util.reportException import org.jetbrains.kotlin.incremental.util.reportException
import java.io.* import java.io.*
@@ -51,7 +52,7 @@ data class BuildInfo(val startTS: Long, val dependencyToAbiSnapshot: Map<String,
it.readBuildInfo() it.readBuildInfo()
} }
} catch (e: Exception) { } catch (e: Exception) {
messageCollector.reportException(e) messageCollector.reportException(e, ExceptionLocation.INCREMENTAL_COMPILATION)
null null
} }
} }
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.incremental.components.ExpectActualTracker
import org.jetbrains.kotlin.incremental.components.LookupTracker import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.incremental.parsing.classesFqNames import org.jetbrains.kotlin.incremental.parsing.classesFqNames
import org.jetbrains.kotlin.incremental.util.BufferingMessageCollector import org.jetbrains.kotlin.incremental.util.BufferingMessageCollector
import org.jetbrains.kotlin.incremental.util.ExceptionLocation
import org.jetbrains.kotlin.incremental.util.reportException import org.jetbrains.kotlin.incremental.util.reportException
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.progress.CompilationCanceledStatus import org.jetbrains.kotlin.progress.CompilationCanceledStatus
@@ -98,7 +99,7 @@ abstract class IncrementalCompilerRunner<
) )
} }
is ICResult.Failed -> { is ICResult.Failed -> {
messageCollector.reportException(result.cause) messageCollector.reportException(result.cause, ExceptionLocation.INCREMENTAL_COMPILATION)
reporter.warn { reporter.warn {
// The indentation after the first line is intentional (so that this message is distinct from next message) // The indentation after the first line is intentional (so that this message is distinct from next message)
""" """
@@ -7,8 +7,13 @@ package org.jetbrains.kotlin.incremental.util
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.cli.common.messages.MessageCollector
public fun MessageCollector.reportException(e: Throwable, location: ExceptionLocation) {
internal fun MessageCollector.reportException(e: Throwable) { report(severity = CompilerMessageSeverity.EXCEPTION, message = "$location failed:${e.message}\n${e.stackTraceToString()}")
report(severity = CompilerMessageSeverity.EXCEPTION, message = "Incremental compilation failed:${e.message}\n${e.stackTraceToString()}") }
public enum class ExceptionLocation(val readablename: String) {
INCREMENTAL_COMPILATION("Incremental compilation"),
DAEMON("Daemon compilation"),
OUT_OF_PROCESS_COMPILATION("Out of process compilation")
} }
@@ -22,6 +22,8 @@ import org.jetbrains.kotlin.gradle.utils.stackTraceAsString
import org.jetbrains.kotlin.incremental.ChangedFiles import org.jetbrains.kotlin.incremental.ChangedFiles
import org.jetbrains.kotlin.incremental.ClasspathChanges import org.jetbrains.kotlin.incremental.ClasspathChanges
import org.jetbrains.kotlin.incremental.IncrementalModuleInfo import org.jetbrains.kotlin.incremental.IncrementalModuleInfo
import org.jetbrains.kotlin.incremental.util.ExceptionLocation
import org.jetbrains.kotlin.incremental.util.reportException
import org.jetbrains.kotlin.util.removeSuffixIfPresent import org.jetbrains.kotlin.util.removeSuffixIfPresent
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import java.io.* import java.io.*
@@ -153,6 +155,7 @@ internal class GradleKotlinCompilerWork @Inject constructor(
try { try {
return compileWithDaemon(messageCollector) to KotlinCompilerExecutionStrategy.DAEMON return compileWithDaemon(messageCollector) to KotlinCompilerExecutionStrategy.DAEMON
} catch (e: Throwable) { } catch (e: Throwable) {
messageCollector.reportException(e, ExceptionLocation.DAEMON)
if (!compilerExecutionSettings.useDaemonFallbackStrategy) { if (!compilerExecutionSettings.useDaemonFallbackStrategy) {
throw RuntimeException( throw RuntimeException(
"Failed to compile with Kotlin daemon. Fallback strategy (compiling without Kotlin daemon) is turned off. " + "Failed to compile with Kotlin daemon. Fallback strategy (compiling without Kotlin daemon) is turned off. " +
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
import org.jetbrains.kotlin.config.KotlinCompilerVersion import org.jetbrains.kotlin.config.KotlinCompilerVersion
import org.jetbrains.kotlin.daemon.client.DaemonReportingTargets import org.jetbrains.kotlin.daemon.client.DaemonReportingTargets
import org.jetbrains.kotlin.daemon.client.launchProcessWithFallback import org.jetbrains.kotlin.daemon.client.launchProcessWithFallback
import org.jetbrains.kotlin.gradle.logging.GradleErrorMessageCollector
import org.jetbrains.kotlin.gradle.logging.GradleKotlinLogger import org.jetbrains.kotlin.gradle.logging.GradleKotlinLogger
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilerExecutionStrategy import org.jetbrains.kotlin.gradle.tasks.KotlinCompilerExecutionStrategy
import org.jetbrains.org.objectweb.asm.ClassReader import org.jetbrains.org.objectweb.asm.ClassReader
@@ -107,13 +108,13 @@ internal fun runToolInSeparateProcess(
compilerClassName, compilerClassName,
"@${compilerOptions.absolutePath}" "@${compilerOptions.absolutePath}"
) )
val messageCollector = createLoggingMessageCollector(logger) val messageCollector = GradleErrorMessageCollector(createLoggingMessageCollector(logger))
val process = launchProcessWithFallback(builder, DaemonReportingTargets(messageCollector = messageCollector)) val process = launchProcessWithFallback(builder, DaemonReportingTargets(messageCollector = messageCollector))
// important to read inputStream, otherwise the process may hang on some systems // important to read inputStream, otherwise the process may hang on some systems
val readErrThread = thread { val readErrThread = thread {
process.errorStream!!.bufferedReader().forEachLine { process.errorStream!!.bufferedReader().forEachLine {
logger.error(it) messageCollector.report(CompilerMessageSeverity.EXCEPTION, it)
} }
} }