[Analysis API] do not rethrow java.lang.Error
Errors as OutOfMemoryError should not be caught or wrapped
This commit is contained in:
committed by
Space Team
parent
9cf77e19be
commit
d7ee312b83
+15
-1
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user