JetBrains / js-graphql-intellij-plugin

GraphQL language support for WebStorm, IntelliJ IDEA and other IDEs based on the IntelliJ Platform.
https://jimkyndemeyer.github.io/js-graphql-intellij-plugin/
MIT License
880 stars 97 forks source link

Plugin stops working if .env contains the same env variable twice #722

Open FrankHeijden opened 2 months ago

FrankHeijden commented 2 months ago

Describe the bug If you use an environment variable in the graphql config which is declared twice in .env, the plugin crashes with no visibility why:

Screenshot 2024-08-28 at 10 52 38

It was easy enough to see from the logs why this happened, but an error / warning would be useful within the IDE why would be a good feature to add :)

Additional context IDE log:

java.lang.IllegalStateException: Duplicate key X (attempted merging values Y and Y)
    at java.base/java.util.stream.Collectors.duplicateKeyException(Collectors.java:135)
    at java.base/java.util.stream.Collectors.lambda$uniqKeysMapAccumulator$1(Collectors.java:182)
    at java.base/java.util.stream.ReduceOps$3ReducingSink.accept(ReduceOps.java:169)
    at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
    at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
    at io.github.cdimascio.dotenv.DotenvBuilder$DotenvImpl.<init>(DotenvBuilder.java:90)
    at io.github.cdimascio.dotenv.DotenvBuilder.load(DotenvBuilder.java:81)
    at com.intellij.lang.jsgraphql.ide.config.env.GraphQLConfigEnvironment.findVariableValueInFile(GraphQLConfigEnvironment.kt:156)
    at com.intellij.lang.jsgraphql.ide.config.env.GraphQLConfigEnvironment.tryToGetVariableFromDotEnvFile(GraphQLConfigEnvironment.kt:128)
    at com.intellij.lang.jsgraphql.ide.config.env.GraphQLConfigEnvironment.getVariable(GraphQLConfigEnvironment.kt:119)
    at com.intellij.lang.jsgraphql.ide.config.env.GraphQLConfigEnvironment.createSnapshot(GraphQLConfigEnvironment.kt:75)
    at com.intellij.lang.jsgraphql.ide.config.model.GraphQLConfig.initProjects(GraphQLConfig.kt:73)
    at com.intellij.lang.jsgraphql.ide.config.model.GraphQLConfig.<init>(GraphQLConfig.kt:46)
    at com.intellij.lang.jsgraphql.ide.config.GraphQLConfigProvider.reload(GraphQLConfigProvider.kt:392)
    at com.intellij.openapi.progress.util.BackgroundTaskUtil.lambda$runUnderDisposeAwareIndicator$15(BackgroundTaskUtil.java:371)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:217)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$13(CoreProgressManager.java:660)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:735)
    at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:691)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:659)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:79)
    at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:202)
    at com.intellij.openapi.progress.util.BackgroundTaskUtil.runUnderDisposeAwareIndicator(BackgroundTaskUtil.java:366)
    at com.intellij.openapi.progress.util.BackgroundTaskUtil.runUnderDisposeAwareIndicator(BackgroundTaskUtil.java:349)
    at com.intellij.lang.jsgraphql.ide.config.GraphQLConfigProvider.scheduleConfigurationReload$lambda$24(GraphQLConfigProvider.kt:361)
    at com.intellij.util.concurrency.ChildContext$runAsCoroutine$1.invoke(propagation.kt:81)
    at com.intellij.util.concurrency.ChildContext$runAsCoroutine$1.invoke(propagation.kt:81)
    at com.intellij.util.concurrency.ChildContext.runAsCoroutine(propagation.kt:86)
    at com.intellij.util.concurrency.ChildContext.runAsCoroutine(propagation.kt:81)
    at com.intellij.util.Alarm$Request.lambda$runSafely$0(Alarm.java:369)
    at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:253)
    at com.intellij.util.Alarm$Request.runSafely(Alarm.java:369)
    at com.intellij.util.Alarm$Request.run(Alarm.java:356)
    at com.intellij.util.concurrency.Propagation.contextAwareCallable$lambda$2(propagation.kt:357)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at com.intellij.util.concurrency.SchedulingWrapper$MyScheduledFutureTask.run(SchedulingWrapper.java:272)
    at com.intellij.util.concurrency.BoundedTaskExecutor.doRun(BoundedTaskExecutor.java:244)
    at com.intellij.util.concurrency.BoundedTaskExecutor.access$200(BoundedTaskExecutor.java:30)
    at com.intellij.util.concurrency.BoundedTaskExecutor$1.executeFirstTaskAndHelpQueue(BoundedTaskExecutor.java:222)
    at com.intellij.util.ConcurrencyUtil.runUnderThreadName(ConcurrencyUtil.java:218)
    at com.intellij.util.concurrency.BoundedTaskExecutor$1.run(BoundedTaskExecutor.java:210)
    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:840)
vepanimas commented 2 months ago

@FrankHeijden thank you for the report! I wasn't aware of that behaviour, I'll check it out. WEB-68976