From edf9e05b1302468ec05b527d4452a6694d774509 Mon Sep 17 00:00:00 2001 From: Ilya Kirillov Date: Sat, 23 Jul 2022 17:04:36 +0200 Subject: [PATCH] Distinguish cause attachments from exception attachments in KotlinExceptionWithAttachments --- .../kotlin/utils/KotlinExceptionWithAttachments.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/compiler/util/src/org/jetbrains/kotlin/utils/KotlinExceptionWithAttachments.kt b/compiler/util/src/org/jetbrains/kotlin/utils/KotlinExceptionWithAttachments.kt index f6d9a4f0022..d903d9e054f 100644 --- a/compiler/util/src/org/jetbrains/kotlin/utils/KotlinExceptionWithAttachments.kt +++ b/compiler/util/src/org/jetbrains/kotlin/utils/KotlinExceptionWithAttachments.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.utils import com.intellij.openapi.diagnostic.Attachment import com.intellij.openapi.diagnostic.ExceptionWithAttachments +import java.nio.charset.StandardCharsets import kotlin.contracts.ExperimentalContracts import kotlin.contracts.contract @@ -17,7 +18,15 @@ open class KotlinExceptionWithAttachments : RuntimeException, ExceptionWithAttac constructor(message: String?, cause: Throwable?) : super(message, cause) { if (cause is KotlinExceptionWithAttachments) { - attachments.addAll(cause.attachments) + attachments.addAll( + cause.attachments.map { a -> + val content = a.openContentStream().use { it.reader(StandardCharsets.UTF_8).use { it.readText() } } + Attachment("case_" + a.path, content) + } + ) + } + if (cause != null) { + withAttachment("causeThrowable", cause.stackTraceToString()) } }