Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in IntelliJ BSP import #2484

Closed
nafg opened this issue Apr 30, 2023 · 14 comments
Closed

Crash in IntelliJ BSP import #2484

nafg opened this issue Apr 30, 2023 · 14 comments
Labels
need-more-info More information is needed to reproduce or fix the issue
Milestone

Comments

@nafg
Copy link
Contributor

nafg commented Apr 30, 2023

I get this in the Build tool window in the Sync tab:

request failed: buildTarget/scalacOptions
bsp error: Internal error. (-32603)

image

I found IntelliJ's BSP trace logs, which includes the response object. It looks like this:

[Trace - 01:05:29 AM] Received response 'buildTarget/scalacOptions - (29)' in 387ms
Result: null
Error: {
  "code": -32603,
  "message": "Internal error.",
  "data": "java.util.concurrent.CompletionException: [...]

It was a long string with a lot of \ns in it. I unescaped it to make it legible:

java.util.concurrent.CompletionException: java.lang.Exception: Failure during task evaluation: app_common.test.compile scala.reflect.internal.MissingRequirementError: object java.lang.Object in compiler mirror not found.
    scala.reflect.internal.MissingRequirementError$.notFound(MissingRequirementError.scala:24)
    scala.reflect.internal.Mirrors$RootsBase.$anonfun$getModuleOrClass$6(Mirrors.scala:63)
    scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:63)
    scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:55)
    scala.reflect.internal.Mirrors$RootsBase.getRequiredClass(Mirrors.scala:55)
    scala.reflect.internal.Definitions$DefinitionsClass.ObjectClass$lzycompute(Definitions.scala:289)
    scala.reflect.internal.Definitions$DefinitionsClass.ObjectClass(Definitions.scala:289)
    scala.reflect.internal.Definitions$DefinitionsClass.init(Definitions.scala:1650)
    scala.tools.nsc.Global$Run.<init>(Global.scala:1236)
    xsbt.ZincCompiler$ZincRun.<init>(CallbackGlobal.scala:80)
    xsbt.CachedCompiler0.run(CompilerBridge.scala:161)
    xsbt.CachedCompiler0.run(CompilerBridge.scala:134)
    xsbt.CompilerBridge.run(CompilerBridge.scala:39)
    sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:91)
    sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$7(MixedAnalyzingCompiler.scala:193)
    scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
    sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:248)
    sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:183)
    sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4$adapted(MixedAnalyzingCompiler.scala:163)
    sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:239)
    sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:163)
    sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:211)
    sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:534)
    sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:534)
    sbt.internal.inc.Incremental$.$anonfun$apply$5(Incremental.scala:179)
    sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:177)
    sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:463)
    sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:116)
    sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:56)
    sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:52)
    sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:263)
    sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:418)
    sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:506)
    sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:405)
    sbt.internal.inc.Incremental$.apply(Incremental.scala:171)
    sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:534)
    sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:488)
    sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332)
    sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:425)
    sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137)
    mill.scalalib.worker.ZincWorkerImpl.compileInternal(ZincWorkerImpl.scala:561)
    mill.scalalib.worker.ZincWorkerImpl.$anonfun$compileMixed0$1(ZincWorkerImpl.scala:339)
    mill.api.FixSizedCache.withCachedValue(FixSizedCache.scala:66)
    mill.scalalib.worker.ZincWorkerImpl.withCompilers(ZincWorkerImpl.scala:421)
    mill.scalalib.worker.ZincWorkerImpl.compileMixed0(ZincWorkerImpl.scala:338)
    mill.scalalib.worker.ZincWorkerImpl.compileMixed(ZincWorkerImpl.scala:306)
    mill.scalalib.ScalaModule.$anonfun$compile$2(ScalaModule.scala:198)
    mill.define.Task$TraverseCtx.evaluate(Task.scala:380)
	at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:332)
	at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:347)
	at java.base/java.util.concurrent.CompletableFuture$UniAccept.tryFire(CompletableFuture.java:708)
	at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510)
	at java.base/java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:2162)
	at mill.bsp.MillBuildServer.$anonfun$completable$1(MillBuildServer.scala:734)
	at mill.bsp.MillBuildServer.$anonfun$completable$1$adapted(MillBuildServer.scala:722)
	at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:484)
	at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1395)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
Caused by: java.lang.Exception: Failure during task evaluation: app_common.test.compile scala.reflect.internal.MissingRequirementError: object java.lang.Object in compiler mirror not found.
    scala.reflect.internal.MissingRequirementError$.notFound(MissingRequirementError.scala:24)
    scala.reflect.internal.Mirrors$RootsBase.$anonfun$getModuleOrClass$6(Mirrors.scala:63)
    scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:63)
    scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:55)
    scala.reflect.internal.Mirrors$RootsBase.getRequiredClass(Mirrors.scala:55)
    scala.reflect.internal.Definitions$DefinitionsClass.ObjectClass$lzycompute(Definitions.scala:289)
    scala.reflect.internal.Definitions$DefinitionsClass.ObjectClass(Definitions.scala:289)
    scala.reflect.internal.Definitions$DefinitionsClass.init(Definitions.scala:1650)
    scala.tools.nsc.Global$Run.<init>(Global.scala:1236)
    xsbt.ZincCompiler$ZincRun.<init>(CallbackGlobal.scala:80)
    xsbt.CachedCompiler0.run(CompilerBridge.scala:161)
    xsbt.CachedCompiler0.run(CompilerBridge.scala:134)
    xsbt.CompilerBridge.run(CompilerBridge.scala:39)
    sbt.internal.inc.AnalyzingCompiler.compile(AnalyzingCompiler.scala:91)
    sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$7(MixedAnalyzingCompiler.scala:193)
    scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
    sbt.internal.inc.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:248)
    sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4(MixedAnalyzingCompiler.scala:183)
    sbt.internal.inc.MixedAnalyzingCompiler.$anonfun$compile$4$adapted(MixedAnalyzingCompiler.scala:163)
    sbt.internal.inc.JarUtils$.withPreviousJar(JarUtils.scala:239)
    sbt.internal.inc.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:163)
    sbt.internal.inc.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:211)
    sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1(IncrementalCompilerImpl.scala:534)
    sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileInternal$1$adapted(IncrementalCompilerImpl.scala:534)
    sbt.internal.inc.Incremental$.$anonfun$apply$5(Incremental.scala:179)
    sbt.internal.inc.Incremental$.$anonfun$apply$5$adapted(Incremental.scala:177)
    sbt.internal.inc.Incremental$$anon$2.run(Incremental.scala:463)
    sbt.internal.inc.IncrementalCommon$CycleState.next(IncrementalCommon.scala:116)
    sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:56)
    sbt.internal.inc.IncrementalCommon$$anon$1.next(IncrementalCommon.scala:52)
    sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:263)
    sbt.internal.inc.Incremental$.$anonfun$incrementalCompile$8(Incremental.scala:418)
    sbt.internal.inc.Incremental$.withClassfileManager(Incremental.scala:506)
    sbt.internal.inc.Incremental$.incrementalCompile(Incremental.scala:405)
    sbt.internal.inc.Incremental$.apply(Incremental.scala:171)
    sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:534)
    sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:488)
    sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:332)
    sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:425)
    sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:137)
    mill.scalalib.worker.ZincWorkerImpl.compileInternal(ZincWorkerImpl.scala:561)
    mill.scalalib.worker.ZincWorkerImpl.$anonfun$compileMixed0$1(ZincWorkerImpl.scala:339)
    mill.api.FixSizedCache.withCachedValue(FixSizedCache.scala:66)
    mill.scalalib.worker.ZincWorkerImpl.withCompilers(ZincWorkerImpl.scala:421)
    mill.scalalib.worker.ZincWorkerImpl.compileMixed0(ZincWorkerImpl.scala:338)
    mill.scalalib.worker.ZincWorkerImpl.compileMixed(ZincWorkerImpl.scala:306)
    mill.scalalib.ScalaModule.$anonfun$compile$2(ScalaModule.scala:198)
    mill.define.Task$TraverseCtx.evaluate(Task.scala:380)
	at mill.eval.Evaluator$.$anonfun$evalOrThrow$default$2$1(Evaluator.scala:1006)
	at mill.eval.Evaluator$EvalOrThrow.apply(Evaluator.scala:995)
	at mill.bsp.MillBuildServer.targetTasks(MillBuildServer.scala:695)
	at mill.bsp.MillScalaBuildServer.$anonfun$buildTargetScalacOptions$1(MillScalaBuildServer.scala:35)
	at mill.bsp.MillBuildServer.$anonfun$completable$1(MillBuildServer.scala:725)
	... 8 more
@nafg
Copy link
Contributor Author

nafg commented Apr 30, 2023

Here is the bsp file contents that IntelliJ is using:

{"name":"mill-bsp","argv":["/home/naftoli/bin/mill","--bsp","--disable-ticker","--color","false","--jobs","1", "--debug"],"millVersion":"0.10.12","bspVersion":"2.0.0","languages":["scala","java"]}

@nafg
Copy link
Contributor Author

nafg commented Apr 30, 2023

I don't know why scalacOptions has to run app_common.test.compile but invoking it manually works:

❯ mill -i app_common.test.compile
[1259/1277] app_common.test.resources 

@nafg
Copy link
Contributor Author

nafg commented Apr 30, 2023

Wait, so then I did another import and checked the last occurence in the logs and it was the same error on a different module (selenium_tests.test.compile), and when I invoked that manually it succeeded, and then I ran import again, and it worked!

@lefou
Copy link
Member

lefou commented May 2, 2023

Could be also IJ, which is in heavy refactoring regarding BSP. What version do you use? Could you cross-check how Metals behaves, e.g. with vscode? You can also inspect .bsp/mill-bsp.stderr to see what Mill reports.

@nafg
Copy link
Contributor Author

nafg commented May 2, 2023

It wasn't generating the stderr file. But this is what intellij says mill actually returned in its response to intellij.

@lefou
Copy link
Member

lefou commented May 3, 2023

That can't be right. If there is no .bsp/mill-bsp.stderr file, IJ is likely not running the Mill BSP server (version 0.10.12) at all. At least, I can't believe right now, that a Mill process is generating the BSP response you posted above. It's more likely the error message comes from IJ directly, but ended in the .trace file. Mill is also writing a BSP trace file to .bsp/mill-bsp.trace. If this isn't there, too, it's an issue in IJ and you should report it there to get it fixed or acknowledged.

@nafg
Copy link
Contributor Author

nafg commented May 3, 2023

I don't remember the exact sequence of events. It was a few days ago, and even after the workaround I described Ctrl-F9 was using the IDEA builder, and it was tedious to do the workaround every time I reimported, so I went back to sbt. So my memory is a little hazy.

However, there sometimes were those files but maybe I had to add --debug for them to get new content. Initially they were there and I deleted them and they didn't come back when I imported, but it's possible it just took a number of tries until IntelliJ was calling it with --debug. Anyway I see those files now and they're huge but I found what seems like the same error in mill-bsp.stderr. I extracted part of it to a gist:

https://gist.github.com/nafg/9ed02e141f5f70ecacadffeb1c9b0f43

@nafg
Copy link
Contributor Author

nafg commented May 3, 2023

Also note that the stack trace shows that it's happening in Mill.

@nafg
Copy link
Contributor Author

nafg commented May 3, 2023

Is there a simple way to test the BSP response with nc or the like?

@lefou
Copy link
Member

lefou commented May 3, 2023

If you start Mill with the --bsp option, it's using STDIN/OUT to speak the Build Server Protocol (BSP) which is based on JSON-RPC. You can then interact with it. Of course you can use nc (netcat) if you know what you're doing.

@lefou
Copy link
Member

lefou commented May 3, 2023

For further analysis, it might be helpful to provide your build.sc.

@lefou lefou added the need-more-info More information is needed to reproduce or fix the issue label May 12, 2023
@nafg
Copy link
Contributor Author

nafg commented May 16, 2023

Hi, sorry for not responding earlier -- I had to switch back to sbt and have been very busy.

Here are the relevant build files: https://gist.github.com/nafg/8bf78893a54fa8ead7d61586cd499880

@nafg
Copy link
Contributor Author

nafg commented May 16, 2023

I'm happy to provide full project access privately if you like

lefou pushed a commit that referenced this issue Jun 30, 2023
Hi! This is my first contribution, so please let me know if there is
anything for me to do.

As far as I understand this is OK, since `bspCompileClasspath` mentions
it tries not to trigger compilation, so the transitive version may also
try not to trigger compilation of the module dependencies.

This would be helpful to us, since we currently cannot load projects in
intellij via bsp if there is a compilation error in any module other
than the topmost module. On the surface this seems similar to the issue
in #2484 (failing on `buildTarget/scalacOptions` due to an error within
`_.compile`).

Pull request: #2646
@lihaoyi lihaoyi added this to the 0.12.0 milestone Oct 17, 2024
@lihaoyi
Copy link
Member

lihaoyi commented Oct 17, 2024

Going to call this hopefully fixed by @alexarchambault 's work adding a coarse grained lock around the out folder

@lihaoyi lihaoyi closed this as completed Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need-more-info More information is needed to reproduce or fix the issue
Projects
None yet
Development

No branches or pull requests

3 participants