User: rednesto Date: 27 Jun 23 15:31 Revision: 23fab598dfca9587166f1ac09b2d8e7fca7c231d Summary: Catch Kotlin plugin errors in more places TeamCity URL: https://ci.mcdev.io/viewModification.html?tab=vcsModificationFiles&modId=8554&personal=false Index: src/main/kotlin/insight/ColorLineMarkerProvider.kt =================================================================== --- src/main/kotlin/insight/ColorLineMarkerProvider.kt (revision df7a52c278bf2e41af801b2e04b662751d86c798) +++ src/main/kotlin/insight/ColorLineMarkerProvider.kt (revision 23fab598dfca9587166f1ac09b2d8e7fca7c231d) @@ -21,6 +21,7 @@ package com.demonwav.mcdev.insight import com.demonwav.mcdev.MinecraftSettings +import com.demonwav.mcdev.util.runCatchingKtIdeaExceptions import com.intellij.codeInsight.daemon.GutterIconNavigationHandler import com.intellij.codeInsight.daemon.LineMarkerInfo import com.intellij.codeInsight.daemon.LineMarkerProvider @@ -52,7 +53,9 @@ } val identifier = element.toUElementOfType() ?: return null - val info = identifier.findColor { map, chosen -> ColorInfo(element, chosen.value, map, chosen.key, identifier) } + val info = runCatchingKtIdeaExceptions { + identifier.findColor { map, chosen -> ColorInfo(element, chosen.value, map, chosen.key, identifier) } + } if (info != null) { NavigateAction.setNavigateAction(info, "Change Color", null) } @@ -164,6 +167,7 @@ } } } + is UCallExpression -> { if (workElement.methodName == "hsvLike") { val (h, s, v) = Color.RGBtoHSB(c.red, c.green, c.blue, null) Index: src/main/kotlin/insight/ColorUtil.kt =================================================================== --- src/main/kotlin/insight/ColorUtil.kt (revision df7a52c278bf2e41af801b2e04b662751d86c798) +++ src/main/kotlin/insight/ColorUtil.kt (revision 23fab598dfca9587166f1ac09b2d8e7fca7c231d) @@ -48,10 +48,12 @@ import org.jetbrains.uast.resolveToUElement fun UIdentifier.findColor(function: (Map, Map.Entry) -> T): T? { + return runCatchingKtIdeaExceptions { - val parent = this.uastParent - val expression = parent as? UReferenceExpression ?: return null + val parent = this.uastParent + val expression = parent as? UReferenceExpression ?: return null - return findColorFromExpression(expression, function) + findColorFromExpression(expression, function) -} + } +} private fun findColorFromExpression( expression: UReferenceExpression, Index: src/main/kotlin/insight/ListenerLineMarkerProvider.kt =================================================================== --- src/main/kotlin/insight/ListenerLineMarkerProvider.kt (revision df7a52c278bf2e41af801b2e04b662751d86c798) +++ src/main/kotlin/insight/ListenerLineMarkerProvider.kt (revision 23fab598dfca9587166f1ac09b2d8e7fca7c231d) @@ -22,6 +22,7 @@ import com.demonwav.mcdev.MinecraftSettings import com.demonwav.mcdev.asset.GeneralAssets +import com.demonwav.mcdev.util.runCatchingKtIdeaExceptions import com.intellij.codeInsight.daemon.GutterIconNavigationHandler import com.intellij.codeInsight.daemon.LineMarkerInfo import com.intellij.codeInsight.daemon.LineMarkerProviderDescriptor @@ -51,20 +52,12 @@ return null } - try { + runCatchingKtIdeaExceptions { val identifier = element.toUElementOfType() ?: return null if (identifier.uastParent !is UMethod || identifier.uastEventListener == null) { return null } - } catch (e: Exception) { - // Kotlin plugin is buggy and can throw exceptions here - // We do the check like this because we don't actually have this class on the classpath - if (e.javaClass.name == "org.jetbrains.kotlin.idea.caches.resolve.KotlinIdeaResolutionException") { - return null - } + } - // Don't swallow unexpected errors - throw e - } // By this point, we can guarantee that the action of "go to declaration" will work // since the PsiClass can be resolved, meaning the event listener is listening to Index: src/main/kotlin/platform/bukkit/BukkitModule.kt =================================================================== --- src/main/kotlin/platform/bukkit/BukkitModule.kt (revision df7a52c278bf2e41af801b2e04b662751d86c798) +++ src/main/kotlin/platform/bukkit/BukkitModule.kt (revision 23fab598dfca9587166f1ac09b2d8e7fca7c231d) @@ -35,6 +35,7 @@ import com.demonwav.mcdev.util.extendsOrImplements import com.demonwav.mcdev.util.findContainingMethod import com.demonwav.mcdev.util.nullable +import com.demonwav.mcdev.util.runCatchingKtIdeaExceptions import com.intellij.lang.jvm.JvmModifier import com.intellij.openapi.project.Project import com.intellij.psi.JavaPsiFacade @@ -182,7 +183,7 @@ val identifier = element?.toUElementOfType() ?: return false - val psiClass = (identifier.uastParent as? UClass)?.javaPsi + val psiClass = runCatchingKtIdeaExceptions { (identifier.uastParent as? UClass)?.javaPsi } ?: return false if (psiClass.hasModifier(JvmModifier.ABSTRACT)) { Index: src/main/kotlin/platform/bungeecord/BungeeCordModule.kt =================================================================== --- src/main/kotlin/platform/bungeecord/BungeeCordModule.kt (revision df7a52c278bf2e41af801b2e04b662751d86c798) +++ src/main/kotlin/platform/bungeecord/BungeeCordModule.kt (revision 23fab598dfca9587166f1ac09b2d8e7fca7c231d) @@ -35,6 +35,7 @@ import com.demonwav.mcdev.util.addImplements import com.demonwav.mcdev.util.extendsOrImplements import com.demonwav.mcdev.util.nullable +import com.demonwav.mcdev.util.runCatchingKtIdeaExceptions import com.intellij.lang.jvm.JvmModifier import com.intellij.psi.JavaPsiFacade import com.intellij.psi.PsiClass @@ -117,7 +118,7 @@ val identifier = element?.toUElementOfType() ?: return false - val psiClass = (identifier.uastParent as? UClass)?.javaPsi + val psiClass = runCatchingKtIdeaExceptions { (identifier.uastParent as? UClass)?.javaPsi } ?: return false val pluginInterface = JavaPsiFacade.getInstance(element.project) Index: src/main/kotlin/platform/fabric/FabricModule.kt =================================================================== --- src/main/kotlin/platform/fabric/FabricModule.kt (revision df7a52c278bf2e41af801b2e04b662751d86c798) +++ src/main/kotlin/platform/fabric/FabricModule.kt (revision 23fab598dfca9587166f1ac09b2d8e7fca7c231d) @@ -28,6 +28,7 @@ import com.demonwav.mcdev.platform.fabric.util.FabricConstants import com.demonwav.mcdev.util.SourceType import com.demonwav.mcdev.util.nullable +import com.demonwav.mcdev.util.runCatchingKtIdeaExceptions import com.intellij.psi.PsiClass import com.intellij.psi.PsiElement import com.intellij.psi.PsiMethod @@ -54,7 +55,7 @@ val identifier = element?.toUElementOfType() ?: return false - val parent = identifier.uastParent + val parent = runCatchingKtIdeaExceptions { identifier.uastParent } if (parent !is UClass && parent !is UMethod) { return false } Index: src/main/kotlin/platform/forge/ForgeModule.kt =================================================================== --- src/main/kotlin/platform/forge/ForgeModule.kt (revision df7a52c278bf2e41af801b2e04b662751d86c798) +++ src/main/kotlin/platform/forge/ForgeModule.kt (revision 23fab598dfca9587166f1ac09b2d8e7fca7c231d) @@ -34,6 +34,7 @@ import com.demonwav.mcdev.util.createVoidMethodWithParameterType import com.demonwav.mcdev.util.extendsOrImplements import com.demonwav.mcdev.util.nullable +import com.demonwav.mcdev.util.runCatchingKtIdeaExceptions import com.demonwav.mcdev.util.runWriteTaskLater import com.demonwav.mcdev.util.waitForAllSmart import com.intellij.json.JsonFileType @@ -187,7 +188,7 @@ val identifier = element?.toUElementOfType() ?: return false - val psiClass = identifier.uastParent as? UClass + val psiClass = runCatchingKtIdeaExceptions { identifier.uastParent as? UClass } ?: return false return !psiClass.hasModifier(JvmModifier.ABSTRACT) && Index: src/main/kotlin/platform/sponge/SpongeModule.kt =================================================================== --- src/main/kotlin/platform/sponge/SpongeModule.kt (revision df7a52c278bf2e41af801b2e04b662751d86c798) +++ src/main/kotlin/platform/sponge/SpongeModule.kt (revision 23fab598dfca9587166f1ac09b2d8e7fca7c231d) @@ -31,6 +31,7 @@ import com.demonwav.mcdev.util.createVoidMethodWithParameterType import com.demonwav.mcdev.util.extendsOrImplements import com.demonwav.mcdev.util.findContainingMethod +import com.demonwav.mcdev.util.runCatchingKtIdeaExceptions import com.intellij.lang.jvm.JvmModifier import com.intellij.psi.JavaPsiFacade import com.intellij.psi.PsiAnnotationMemberValue @@ -93,9 +94,9 @@ val identifier = element?.toUElementOfType() ?: return false - val psiClass = identifier.uastParent as? UClass ?: return false + val psiClass = runCatchingKtIdeaExceptions { identifier.uastParent as? UClass ?: return false } - if (psiClass.javaPsi.hasModifier(JvmModifier.ABSTRACT)) { + if (psiClass == null || psiClass.javaPsi.hasModifier(JvmModifier.ABSTRACT)) { return false } Index: src/main/kotlin/platform/velocity/VelocityModule.kt =================================================================== --- src/main/kotlin/platform/velocity/VelocityModule.kt (revision df7a52c278bf2e41af801b2e04b662751d86c798) +++ src/main/kotlin/platform/velocity/VelocityModule.kt (revision 23fab598dfca9587166f1ac09b2d8e7fca7c231d) @@ -29,6 +29,7 @@ import com.demonwav.mcdev.platform.velocity.util.VelocityConstants import com.demonwav.mcdev.platform.velocity.util.VelocityConstants.SUBSCRIBE_ANNOTATION import com.demonwav.mcdev.util.createVoidMethodWithParameterType +import com.demonwav.mcdev.util.runCatchingKtIdeaExceptions import com.intellij.lang.jvm.JvmModifier import com.intellij.psi.JavaPsiFacade import com.intellij.psi.PsiClass @@ -75,7 +76,7 @@ val identifier = element?.toUElementOfType() ?: return false - val psiClass = identifier.uastParent as? UClass + val psiClass = runCatchingKtIdeaExceptions { identifier.uastParent as? UClass } ?: return false return !psiClass.hasModifier(JvmModifier.ABSTRACT) && Index: src/main/kotlin/util/utils.kt =================================================================== --- src/main/kotlin/util/utils.kt (revision df7a52c278bf2e41af801b2e04b662751d86c798) +++ src/main/kotlin/util/utils.kt (revision 23fab598dfca9587166f1ac09b2d8e7fca7c231d) @@ -365,6 +365,7 @@ action() } catch (e: Exception) { if (e.javaClass.name == "org.jetbrains.kotlin.idea.caches.resolve.KotlinIdeaResolutionException") { + loggerForTopLevel().info("Caught Kotlin plugin exception", e) null } else { throw e