From e3c31e1387d53f75450b7fbf6fb1d9216c5c4dba Mon Sep 17 00:00:00 2001 From: Ilya Kirillov Date: Fri, 30 Jun 2023 15:51:59 +0200 Subject: [PATCH] Introduce exception-specific exception classes for KotlinExceptionWithAttachments --- .../exceptions/ExceptionAttachmentBuilder.kt | 3 +- .../KotlinExceptionWithAttachments.kt | 34 ++++++++++++++++++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/compiler/util/src/org/jetbrains/kotlin/utils/exceptions/ExceptionAttachmentBuilder.kt b/compiler/util/src/org/jetbrains/kotlin/utils/exceptions/ExceptionAttachmentBuilder.kt index cf02047dfbf..799cccd301f 100644 --- a/compiler/util/src/org/jetbrains/kotlin/utils/exceptions/ExceptionAttachmentBuilder.kt +++ b/compiler/util/src/org/jetbrains/kotlin/utils/exceptions/ExceptionAttachmentBuilder.kt @@ -7,7 +7,6 @@ package org.jetbrains.kotlin.utils.exceptions import com.intellij.openapi.diagnostic.Attachment import com.intellij.openapi.diagnostic.Logger -import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments import org.jetbrains.kotlin.utils.SmartPrinter import org.jetbrains.kotlin.utils.withIndent import kotlin.contracts.ExperimentalContracts @@ -65,7 +64,7 @@ inline fun buildErrorWithAttachment( attachmentName: String = "info.txt", buildAttachment: ExceptionAttachmentBuilder.() -> Unit = {}, ): Nothing { - val exception = KotlinExceptionWithAttachments(message, cause) + val exception = KotlinIllegalArgumentExceptionWithAttachments(message, cause) exception.buildAttachment(attachmentName) { buildAttachment() } throw exception } diff --git a/compiler/util/src/org/jetbrains/kotlin/utils/exceptions/KotlinExceptionWithAttachments.kt b/compiler/util/src/org/jetbrains/kotlin/utils/exceptions/KotlinExceptionWithAttachments.kt index 122527fafa4..2f03ff417a4 100644 --- a/compiler/util/src/org/jetbrains/kotlin/utils/exceptions/KotlinExceptionWithAttachments.kt +++ b/compiler/util/src/org/jetbrains/kotlin/utils/exceptions/KotlinExceptionWithAttachments.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.utils.exceptions import com.intellij.openapi.diagnostic.Attachment import com.intellij.openapi.diagnostic.ExceptionWithAttachments +import org.jetbrains.kotlin.utils.exceptions.KotlinExceptionWithAttachments.Companion.withAttachmentsFrom import java.nio.charset.StandardCharsets interface KotlinExceptionWithAttachments : ExceptionWithAttachments { @@ -36,4 +37,35 @@ interface KotlinExceptionWithAttachments : ExceptionWithAttachments { return Attachment(newName, content) } } -} \ No newline at end of file +} + +open class KotlinIllegalStateExceptionWithAttachments : IllegalStateException, KotlinExceptionWithAttachments { + final override val mutableAttachments = mutableListOf() + + constructor(message: String) : super(message) + + constructor(message: String?, cause: Throwable?) : super(message, cause) { + withAttachmentsFrom(cause) + } +} + +open class KotlinRuntimeExceptionWithAttachments : RuntimeException, KotlinExceptionWithAttachments { + final override val mutableAttachments = mutableListOf() + + constructor(message: String) : super(message) + + constructor(message: String?, cause: Throwable?) : super(message, cause) { + withAttachmentsFrom(cause) + } +} + +open class KotlinIllegalArgumentExceptionWithAttachments : IllegalArgumentException, KotlinExceptionWithAttachments { + final override val mutableAttachments = mutableListOf() + + constructor(message: String) : super(message) + + constructor(message: String?, cause: Throwable?) : super(message, cause) { + withAttachmentsFrom(cause) + } +} +