Lordfirespeed / intellij-typescript-run-configuration

IntelliJ IDEA (and WebStorm...) plugin to support 'TypeScript' as a run configuration
https://plugins.jetbrains.com/plugin/10841-run-configuration-for-typescript
3 stars 0 forks source link

Regularly occurring error #2

Open Lordfirespeed opened 1 year ago

Lordfirespeed commented 1 year ago
java.lang.NullPointerException: psiFile must not be null
    at com.github.lordfirespeed.intellij_typescript_run_configuration.typescript.runconfig.TSRunConfigurationProducer.setupConfigurationFromContext(TSRunConfigurationProducer.kt:25)
    at com.github.lordfirespeed.intellij_typescript_run_configuration.typescript.runconfig.TSRunConfigurationProducer.setupConfigurationFromContext(TSRunConfigurationProducer.kt:12)
    at com.intellij.execution.actions.RunConfigurationProducer.createConfigurationFromContext(RunConfigurationProducer.java:100)
    at com.intellij.execution.actions.RunConfigurationProducer.findOrCreateConfigurationFromContext(RunConfigurationProducer.java:197)
    at com.intellij.execution.actions.PreferredProducerFind.doGetConfigurationsFromContext(PreferredProducerFind.java:118)
    at com.intellij.execution.actions.PreferredProducerFind.getConfigurationsFromContext(PreferredProducerFind.java:100)
    at com.intellij.execution.actions.PreferredProducerFind.createConfiguration(PreferredProducerFind.java:32)
    at com.intellij.execution.actions.ConfigurationContext.createConfiguration(ConfigurationContext.java:204)
    at com.intellij.execution.actions.ConfigurationContext.getConfiguration(ConfigurationContext.java:195)
    at com.intellij.execution.actions.BaseRunConfigurationAction.fullUpdate(BaseRunConfigurationAction.java:221)
    at com.intellij.execution.actions.BaseRunConfigurationAction.update(BaseRunConfigurationAction.java:183)
    at com.intellij.openapi.actionSystem.ex.ActionUtil.lambda$performDumbAwareUpdate$0(ActionUtil.java:159)
    at com.intellij.openapi.actionSystem.ex.ActionUtil.performDumbAwareUpdate(ActionUtil.java:182)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.doUpdate(ActionUpdater.java:740)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.lambda$updateActionReal$4(ActionUpdater.java:145)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.lambda$callAction$5(ActionUpdater.java:195)
    at com.intellij.platform.diagnostic.telemetry.helpers.TraceKt.computeWithSpan(trace.kt:171)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.callAction(ActionUpdater.java:191)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.callAction(ActionUpdater.java:170)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.updateActionReal(ActionUpdater.java:146)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.lambda$new$0(ActionUpdater.java:132)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.update(ActionUpdater.java:725)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.expandGroupChild(ActionUpdater.java:566)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.lambda$doExpandActionGroup$22(ActionUpdater.java:531)
    at com.intellij.util.containers.ContainerUtil.concat(ContainerUtil.java:1539)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.doExpandActionGroup(ActionUpdater.java:531)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.expandGroupChild(ActionUpdater.java:622)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.lambda$doExpandActionGroup$22(ActionUpdater.java:531)
    at com.intellij.util.containers.ContainerUtil.concat(ContainerUtil.java:1539)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.doExpandActionGroup(ActionUpdater.java:531)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.expandGroupChild(ActionUpdater.java:622)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.lambda$doExpandActionGroup$22(ActionUpdater.java:531)
    at com.intellij.util.containers.ContainerUtil.concat(ContainerUtil.java:1539)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.doExpandActionGroup(ActionUpdater.java:531)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.expandGroupChild(ActionUpdater.java:622)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.lambda$doExpandActionGroup$22(ActionUpdater.java:531)
    at com.intellij.util.containers.ContainerUtil.concat(ContainerUtil.java:1539)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.doExpandActionGroup(ActionUpdater.java:531)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.expandGroupChild(ActionUpdater.java:622)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.lambda$doExpandActionGroup$22(ActionUpdater.java:531)
    at com.intellij.util.containers.ContainerUtil.concat(ContainerUtil.java:1539)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.doExpandActionGroup(ActionUpdater.java:531)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.expandActionGroup(ActionUpdater.java:315)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.lambda$doExpandActionGroupAsync$14(ActionUpdater.java:382)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.lambda$doExpandActionGroupAsync$15(ActionUpdater.java:403)
    at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1133)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.lambda$tryRunReadActionAndCancelBeforeWrite$19(ActionUpdater.java:435)
    at com.intellij.openapi.progress.util.ProgressIndicatorUtilService.runActionAndCancelBeforeWrite(ProgressIndicatorUtilService.java:63)
    at com.intellij.openapi.progress.util.ProgressIndicatorUtils.runActionAndCancelBeforeWrite(ProgressIndicatorUtils.java:133)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.tryRunReadActionAndCancelBeforeWrite(ActionUpdater.java:431)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.lambda$doExpandActionGroupAsync$16(ActionUpdater.java:403)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:186)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$13(CoreProgressManager.java:604)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:679)
    at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:635)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:603)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:61)
    at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:173)
    at com.intellij.openapi.progress.util.BackgroundTaskUtil.runUnderDisposeAwareIndicator(BackgroundTaskUtil.java:360)
    at com.intellij.openapi.actionSystem.impl.ActionUpdater.lambda$doExpandActionGroupAsync$17(ActionUpdater.java:402)
    at io.opentelemetry.context.Context.lambda$wrap$1(Context.java:212)
    at com.intellij.util.concurrency.BoundedTaskExecutor.doRun(BoundedTaskExecutor.java:249)
    at com.intellij.util.concurrency.BoundedTaskExecutor.access$200(BoundedTaskExecutor.java:31)
    at com.intellij.util.concurrency.BoundedTaskExecutor$1.executeFirstTaskAndHelpQueue(BoundedTaskExecutor.java:227)
    at com.intellij.util.ConcurrencyUtil.runUnderThreadName(ConcurrencyUtil.java:218)
    at com.intellij.util.concurrency.BoundedTaskExecutor$1.run(BoundedTaskExecutor.java:215)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:702)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:699)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:699)
    at java.base/java.lang.Thread.run(Thread.java:833)
Lordfirespeed commented 11 months ago

Error seems to arise here: https://github.com/Lordfirespeed/intellij-typescript-run-configuration/blob/26db4921ba3e2638eb0f04b9936b3588099f42b1/src/main/kotlin/com/github/lordfirespeed/intellij_typescript_run_configuration/typescript/runconfig/TSRunConfigurationProducer.kt#L15-L31

Specifically, the Ref<PsiElement> can be Ref<null> :boom:

However, TsExecuteUtil.isTypeScript(PsiFile) does not accept nullable: https://github.com/Lordfirespeed/intellij-typescript-run-configuration/blob/26db4921ba3e2638eb0f04b9936b3588099f42b1/src/main/kotlin/com/github/lordfirespeed/intellij_typescript_run_configuration/typescript/TSExecuteUtil.kt#L56-L60

I believe it should be sufficient to implement an overload isTypeScript(PsiFile?) that null-checks before delegating to isTypeScript(PsiFile).

Lordfirespeed commented 11 months ago

See here for base method docstring.

See here for example implementation.

Lordfirespeed commented 11 months ago

Also, quick sanity check: I copied this implementation from an old version of run configurations for Node or NPM or something.

Why am I using context.location? Going off createConfigurationFromContext, it seems that the passed Ref<PsiElement> is just the wrapped value of context.location.