Check also the cause of throwable for OOM exception

Sometimes OOM exception is the cause of some higher-level one
exception in compilation.

^KT-51116 Fixed
This commit is contained in:
Yahor Berdnikau
2022-02-03 13:24:53 +01:00
committed by Space
parent 5b79279590
commit 5320a32d67
@@ -121,12 +121,17 @@ abstract class CLICompiler<A : CommonCompilerArguments> : CLITool<A>() {
return COMPILATION_ERROR
} catch (t: Throwable) {
MessageCollectorUtil.reportException(collector, t)
return if (t is OutOfMemoryError) OOM_ERROR else INTERNAL_ERROR
return if (t is OutOfMemoryError || t.hasOOMCause()) OOM_ERROR else INTERNAL_ERROR
} finally {
collector.flush()
}
}
private fun Throwable.hasOOMCause(): Boolean = when (cause) {
is OutOfMemoryError -> true
else -> cause?.hasOOMCause() ?: false
}
private fun MessageCollector.reportCompilationCancelled(e: CompilationCanceledException) {
if (e !is IncrementalNextRoundException) {
report(INFO, "Compilation was canceled", null)