[Analysis API] do not rethrow java.lang.Error

Errors as OutOfMemoryError should not be caught or wrapped
This commit is contained in:
Ilya Kirillov
2022-12-13 13:15:48 +01:00
committed by Space Team
parent 9cf77e19be
commit d7ee312b83
6 changed files with 34 additions and 27 deletions
@@ -7,6 +7,8 @@ package org.jetbrains.kotlin.analysis.utils.errors
import org.jetbrains.kotlin.analysis.utils.printer.PrettyPrinter
import org.jetbrains.kotlin.analysis.utils.printer.prettyPrint
import org.jetbrains.kotlin.util.SourceCodeAnalysisException
import org.jetbrains.kotlin.util.shouldIjPlatformExceptionBeRethrown
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract
@@ -59,7 +61,7 @@ public inline fun KotlinExceptionWithAttachments.buildAttachment(
public inline fun buildErrorWithAttachment(
message: String,
cause: Throwable? = null,
cause: Exception? = null,
attachmentName: String = "info.txt",
buildAttachment: ExceptionAttachmentBuilder.() -> Unit = {}
): Nothing {
@@ -68,6 +70,18 @@ public inline fun buildErrorWithAttachment(
throw exception
}
public inline fun rethrowExceptionWithDetails(
message: String,
exception: Exception,
attachmentName: String = "info.txt",
buildAttachment: ExceptionAttachmentBuilder.() -> Unit = {}
): Nothing {
if (shouldIjPlatformExceptionBeRethrown(exception)) throw exception
val unwrappedException = if (exception is SourceCodeAnalysisException) exception.cause else exception
if (unwrappedException !is Exception) throw unwrappedException
buildErrorWithAttachment(message, unwrappedException, attachmentName, buildAttachment)
}
@OptIn(ExperimentalContracts::class)
public inline fun checkWithAttachmentBuilder(