Skip to content

Commit 7fc4064

Browse files
Minor: clarify exception messages during Evaluate Expression
1 parent d40cd05 commit 7fc4064

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

idea/src/org/jetbrains/kotlin/idea/debugger/evaluate/KotlinEvaluationBuilder.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ class KotlinEvaluator(val codeFragment: KtCodeFragment, val sourcePosition: Sour
156156

157157
val attachments = arrayOf(attachmentByPsiFile(sourcePosition.file),
158158
attachmentByPsiFile(codeFragment),
159-
Attachment("breakpoint.info", "line: ${sourcePosition.line}"))
159+
Attachment("breakpoint.info", "line: ${sourcePosition.line}"),
160+
Attachment("context.info", codeFragment.context?.text ?: "null"))
160161
LOG.error(LogMessageEx.createEvent(
161162
"Couldn't evaluate expression",
162163
ExceptionUtil.getThrowableText(e),

idea/src/org/jetbrains/kotlin/idea/debugger/evaluate/extractFunctionForDebuggerUtil.kt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717
package org.jetbrains.kotlin.idea.debugger.evaluate
1818

1919
import com.intellij.debugger.engine.evaluation.EvaluateExceptionUtil
20+
import com.intellij.diagnostic.LogMessageEx
21+
import com.intellij.openapi.diagnostic.Attachment
2022
import com.intellij.openapi.util.Key
2123
import com.intellij.psi.PsiElement
2224
import com.intellij.psi.PsiFile
2325
import com.intellij.psi.PsiManager
2426
import com.intellij.psi.impl.PsiModificationTrackerImpl
27+
import com.intellij.util.ExceptionUtil
2528
import org.jetbrains.kotlin.idea.actions.internal.KotlinInternalMode
2629
import org.jetbrains.kotlin.idea.caches.resolve.analyze
2730
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFullyAndGetResult
@@ -32,6 +35,8 @@ import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.*
3235
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.AnalysisResult.ErrorMessage
3336
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.AnalysisResult.Status
3437
import org.jetbrains.kotlin.idea.util.application.runReadAction
38+
import org.jetbrains.kotlin.idea.util.attachment.attachmentByPsiFile
39+
import org.jetbrains.kotlin.idea.util.attachment.mergeAttachments
3540
import org.jetbrains.kotlin.idea.util.psi.patternMatching.toRange
3641
import org.jetbrains.kotlin.psi.*
3742
import org.jetbrains.kotlin.psi.codeFragmentUtil.suppressDiagnosticsInDebugMode
@@ -49,13 +54,16 @@ fun getFunctionForExtractedFragment(
4954

5055
fun getErrorMessageForExtractFunctionResult(analysisResult: AnalysisResult, tmpFile: KtFile): String {
5156
if (KotlinInternalMode.enabled) {
52-
LOG.error("Couldn't extract function for debugger:\n" +
53-
"FILE NAME: ${breakpointFile.name}\n" +
54-
"BREAKPOINT LINE: $breakpointLine\n" +
55-
"CODE FRAGMENT:\n${codeFragment.text}\n" +
56-
"ERRORS:\n${analysisResult.messages.map { "$it: ${it.renderMessage()}" }.joinToString("\n")}\n" +
57-
"TMPFILE_TEXT:\n${tmpFile.text}\n" +
58-
"FILE TEXT: \n${breakpointFile.text}\n")
57+
val attachments = arrayOf(attachmentByPsiFile(tmpFile),
58+
attachmentByPsiFile(breakpointFile),
59+
attachmentByPsiFile(codeFragment),
60+
Attachment("breakpoint.info", "line: $breakpointLine"),
61+
Attachment("context.info", codeFragment.context?.text ?: "null"),
62+
Attachment("errors.info", analysisResult.messages.map { "$it: ${it.renderMessage()}" }.joinToString("\n")))
63+
LOG.error(LogMessageEx.createEvent(
64+
"Internal error during evaluate expression",
65+
ExceptionUtil.getThrowableText(Throwable("Extract function fails with ${analysisResult.messages.joinToString { it.name }}")),
66+
mergeAttachments(*attachments)))
5967
}
6068
return analysisResult.messages.map { errorMessage ->
6169
val message = when(errorMessage) {

idea/src/org/jetbrains/kotlin/idea/util/attachment/attachmentUtils.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
package org.jetbrains.kotlin.idea.util.attachment
1818

19-
import com.intellij.psi.PsiFile
20-
import com.intellij.openapi.diagnostic.Attachment
2119
import com.intellij.diagnostic.AttachmentFactory
20+
import com.intellij.openapi.diagnostic.Attachment
21+
import com.intellij.psi.PsiFile
2222

2323
fun attachmentByPsiFileAsArray(file: PsiFile?): Array<Attachment> {
2424
val attachment = attachmentByPsiFile(file)
@@ -48,9 +48,9 @@ fun mergeAttachments(vararg attachments: Attachment?): Attachment {
4848
val builder = StringBuilder()
4949
attachments.forEach {
5050
if (it != null) {
51-
builder.append("\n----- START ${it.path} -----\n")
51+
builder.append("----- START ${it.path} -----\n")
5252
builder.append(it.displayText)
53-
builder.append("\n----- END ${it.path} -----\n")
53+
builder.append("\n----- END ${it.path} -----\n\n")
5454
}
5555
}
5656

0 commit comments

Comments
 (0)