[FIR] KT-44698: Print file:line:offset on K2 crash
^KT-44698 Fixed
This commit is contained in:
@@ -9,6 +9,7 @@ import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.progress.ProcessCanceledException
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.util.SourceCodeAnalysisException
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
@@ -233,13 +234,24 @@ object CodegenUtil {
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun reportBackendException(exception: Throwable, phase: String, location: String?, additionalMessage: String? = null): Nothing {
|
||||
fun reportBackendException(
|
||||
exception: Throwable,
|
||||
phase: String,
|
||||
location: String?,
|
||||
additionalMessage: String? = null,
|
||||
linesMapping: (Int) -> Pair<Int, Int>? = { _ -> null },
|
||||
): Nothing {
|
||||
// CompilationException (the only KotlinExceptionWithAttachments possible here) is already supposed
|
||||
// to have all information about the context.
|
||||
if (exception is KotlinExceptionWithAttachments) throw exception
|
||||
if (exception is ProcessCanceledException) throw exception
|
||||
val locationWithLineAndOffset = location
|
||||
?.let { exception as? SourceCodeAnalysisException }
|
||||
?.let { linesMapping(it.source.startOffset) }
|
||||
?.let { (line, offset) -> "$location:${line + 1}:${offset + 1}" }
|
||||
?: location
|
||||
throw BackendException(
|
||||
getExceptionMessage("Backend", "Exception during $phase", exception, location) +
|
||||
getExceptionMessage("Backend", "Exception during $phase", exception, locationWithLineAndOffset) +
|
||||
additionalMessage?.let { "\n" + it }.orEmpty(),
|
||||
exception
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user