From 8825cf7bf6889c806f5e80389437cd94f52cf15f Mon Sep 17 00:00:00 2001 From: "Alexander.Likhachev" Date: Mon, 30 Jan 2023 21:18:33 +0100 Subject: [PATCH] [IC] Fix RecoverableCompilationTransaction wasn't throwing an exception properly #KT-56052 In Progress --- .../kotlin/incremental/CompilationTransaction.kt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/build-common/src/org/jetbrains/kotlin/incremental/CompilationTransaction.kt b/build-common/src/org/jetbrains/kotlin/incremental/CompilationTransaction.kt index 809b96a1fb9..0b57b5e80a0 100644 --- a/build-common/src/org/jetbrains/kotlin/incremental/CompilationTransaction.kt +++ b/build-common/src/org/jetbrains/kotlin/incremental/CompilationTransaction.kt @@ -240,17 +240,21 @@ class RecoverableCompilationTransaction( override fun close() { val mainException = closeCachesManager() - - try { + val exceptionToThrow = runCatching { if (isSuccessful) { cleanupStash() } else { revertChanges() cleanupStash() } - } catch (t: Throwable) { - mainException?.addSuppressed(t) - throw mainException ?: t + }.exceptionOrNull().run { + if (this != null) { + mainException?.addSuppressed(this) + } + mainException ?: this + } + if (exceptionToThrow != null) { + throw exceptionToThrow } } }