From 955520f69eb038cc942792cad5a0d22794c6c173 Mon Sep 17 00:00:00 2001 From: Stanislav Erokhin Date: Wed, 19 Jul 2023 15:21:27 +0200 Subject: [PATCH] [Gradle] Fix the verbose rendering for FATAL diagnostics During the tests we are using the verbose way of render the diagnostic meaning, that we are adding the diagnostic id to the diagnostic message. And we previously didn't have that for one case, so we were unable to detect in tests that diagnostic with FATAL severity was reported --- .../diagnostics/KotlinToolingDiagnosticsCollector.kt | 9 ++++----- .../plugin/diagnostics/renderReportedDiagnostics.kt | 10 +++++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/diagnostics/KotlinToolingDiagnosticsCollector.kt b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/diagnostics/KotlinToolingDiagnosticsCollector.kt index 4e728f02543..e0780d6cd7e 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/diagnostics/KotlinToolingDiagnosticsCollector.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/diagnostics/KotlinToolingDiagnosticsCollector.kt @@ -5,7 +5,6 @@ package org.jetbrains.kotlin.gradle.plugin.diagnostics -import org.gradle.api.InvalidUserCodeException import org.gradle.api.Project import org.gradle.api.provider.Provider import org.gradle.api.services.BuildService @@ -63,8 +62,10 @@ internal abstract class KotlinToolingDiagnosticsCollector : BuildService logger.error("e: ${diagnostic.render(isVerbose)}\n") - FATAL -> if (diagnostic.throwable != null) - throw InvalidUserCodeException(diagnostic.render(isVerbose), diagnostic.throwable) - else throw InvalidUserCodeException(diagnostic.render(isVerbose)) + FATAL -> throw diagnostic.createAnExceptionForFatalDiagnostic(isVerbose) } } +internal fun ToolingDiagnostic.createAnExceptionForFatalDiagnostic(isVerbose: Boolean): InvalidUserCodeException = + if (throwable != null) + InvalidUserCodeException(render(isVerbose), throwable) + else + InvalidUserCodeException(render(isVerbose)) + private fun ToolingDiagnostic.render(isVerbose: Boolean): String = buildString { if (isVerbose) { appendLine(this@render)