[IR] Do best effort explaining IR linker issue to the user if computation of the detailed IR linker error message failed due to unexpected error

Related to #KT-50591
This commit is contained in:
Dmitriy Dolovov
2022-01-10 13:50:09 +03:00
parent cb5a052227
commit 716ca3c319
@@ -19,21 +19,37 @@ import org.jetbrains.kotlin.utils.ResolvedDependencyVersion
import kotlin.Comparator import kotlin.Comparator
abstract class KotlinIrLinkerIssue { abstract class KotlinIrLinkerIssue {
protected abstract val message: String protected abstract val errorMessage: String
fun raiseIssue(messageLogger: IrMessageLogger): KotlinIrLinkerInternalException { fun raiseIssue(messageLogger: IrMessageLogger): KotlinIrLinkerInternalException {
messageLogger.report(IrMessageLogger.Severity.ERROR, message, null) messageLogger.report(IrMessageLogger.Severity.ERROR, errorMessage, null)
throw KotlinIrLinkerInternalException() throw KotlinIrLinkerInternalException()
} }
} }
class SignatureIdNotFoundInModuleWithDependencies( class SignatureIdNotFoundInModuleWithDependencies(
idSignature: IdSignature, private val idSignature: IdSignature,
problemModuleDeserializer: IrModuleDeserializer, private val problemModuleDeserializer: IrModuleDeserializer,
allModuleDeserializers: Collection<IrModuleDeserializer>, private val allModuleDeserializers: Collection<IrModuleDeserializer>,
userVisibleIrModulesSupport: UserVisibleIrModulesSupport private val userVisibleIrModulesSupport: UserVisibleIrModulesSupport
) : KotlinIrLinkerIssue() { ) : KotlinIrLinkerIssue() {
override val message = buildString { override val errorMessage = try {
computeErrorMessage()
} catch (e: Throwable) {
// Don't suppress the real cause if computation of error message failed.
throw RuntimeException(
buildString {
appendLine("Failed to compute the detailed error message. See the root cause exception.")
appendLine()
append("Shortly: The required symbol ${idSignature.render()} is missing in the module or module dependencies.")
append(" This could happen if the required dependency is missing in the project.")
append(" Or if there is a dependency that has a different version (without the required symbol) in the project")
append(" than the version (with the required symbol) that the module was initially compiled with.")
}
)
}
private fun computeErrorMessage() = buildString {
val allModules = userVisibleIrModulesSupport.getUserVisibleModules(allModuleDeserializers) val allModules = userVisibleIrModulesSupport.getUserVisibleModules(allModuleDeserializers)
val problemModuleId = userVisibleIrModulesSupport.getProblemModuleId(problemModuleDeserializer, allModules) val problemModuleId = userVisibleIrModulesSupport.getProblemModuleId(problemModuleDeserializer, allModules)
@@ -74,18 +90,25 @@ class SignatureIdNotFoundInModuleWithDependencies(
} }
class NoDeserializerForModule(moduleName: Name, idSignature: IdSignature?) : KotlinIrLinkerIssue() { class NoDeserializerForModule(moduleName: Name, idSignature: IdSignature?) : KotlinIrLinkerIssue() {
override val message = buildString { override val errorMessage = buildString {
append("Could not load module ${moduleName.asString()}") append("Could not load module ${moduleName.asString()}")
if (idSignature != null) append(" in an attempt to find deserializer for symbol ${idSignature.render()}.") if (idSignature != null) append(" in an attempt to find deserializer for symbol ${idSignature.render()}.")
} }
} }
class SymbolTypeMismatch( class SymbolTypeMismatch(
cause: IrSymbolTypeMismatchException, private val cause: IrSymbolTypeMismatchException,
allModuleDeserializers: Collection<IrModuleDeserializer>, private val allModuleDeserializers: Collection<IrModuleDeserializer>,
userVisibleIrModulesSupport: UserVisibleIrModulesSupport private val userVisibleIrModulesSupport: UserVisibleIrModulesSupport
) : KotlinIrLinkerIssue() { ) : KotlinIrLinkerIssue() {
override val message: String = buildString { override val errorMessage = try {
computeErrorMessage()
} catch (e: Throwable) {
// Don't suppress the real cause if computation of error message failed.
throw if (e === cause) e else e.apply { addSuppressed(cause) }
}
private fun computeErrorMessage() = buildString {
val allModules = userVisibleIrModulesSupport.getUserVisibleModules(allModuleDeserializers) val allModules = userVisibleIrModulesSupport.getUserVisibleModules(allModuleDeserializers)
val idSignature = cause.actual.signature val idSignature = cause.actual.signature