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

buildTarget/cleanCache throws an error #2915

Closed
ckipp01 opened this issue Dec 8, 2023 · 0 comments · Fixed by #2931
Closed

buildTarget/cleanCache throws an error #2915

ckipp01 opened this issue Dec 8, 2023 · 0 comments · Fixed by #2931
Milestone

Comments

@ckipp01
Copy link
Contributor

ckipp01 commented Dec 8, 2023

When using Mill as a BSP server I noticed that I'm getting an internal error when I try to do a clean compile. For example in the logs I see

[Trace - 02:09:53 pm] Sending request 'buildTarget/cleanCache - (24)'
Params: {
  "targets": [
    {
      "uri": "file:///Users/ckipp/Documents/scala-workspace/mill-plugins/mill-giter8/plugin/0.10"
    },
    {
      "uri": "file:///Users/ckipp/Documents/scala-workspace/mill-plugins/mill-giter8/plugin/0.11"
    },
    {
      "uri": "file:///Users/ckipp/Documents/scala-workspace/mill-plugins/mill-giter8/mill-build"
    }
  ]
}

...

[Trace - 02:09:53 pm] Received response 'buildTarget/cleanCache - (24)' in 4ms
Result: null
Error: {
  "code": -32603,
  "message": "Internal error.",
  "data": "java.util.concurrent.CompletionException: scala.MatchError:  (of class millbuild.build$)\n\tat java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:332)\n\tat java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:347)\n\tat java.base/java.util.concurrent.CompletableFuture$UniAccept.tryFire(CompletableFuture.java:708)\n\tat java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510)\n\tat java.base/java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:2162)\n\tat mill.bsp.worker.MillBuildServer.$anonfun$completable$1(MillBuildServer.scala:708)\n\tat mill.bsp.worker.MillBuildServer.$anonfun$completable$1$adapted(MillBuildServer.scala:696)\n\tat scala.concurrent.impl.Promise$Transformation.run(Promise.scala:484)\n\tat java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1395)\n\tat java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)\n\tat java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)\n\tat java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)\n\tat java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)\n\tat java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)\nCaused by: scala.MatchError:  (of class millbuild.build$)\n\tat mill.bsp.worker.MillBuildServer.$anonfun$buildTargetCleanCache$2(MillBuildServer.scala:595)\n\tat scala.collection.immutable.List.map(List.scala:246)\n\tat scala.collection.immutable.List.map(List.scala:79)\n\tat mill.bsp.worker.MillBuildServer.$anonfun$buildTargetCleanCache$1(MillBuildServer.scala:595)\n\tat mill.bsp.worker.MillBuildServer.$anonfun$completable$1(MillBuildServer.scala:699)\n\t... 8 more\n"
}

This then causes the compilation to be cancelled in the clean compile command.

To reproduce

  1. Make a simple hello world project
  2. Open with Metals and make sure everything is imported while using Mill as your build server
  3. Create a .metals/bsp.trace.json file
  4. Restart the build server
  5. Trigger a Metals Clean Compile command
  6. See error above in logs
ckipp01 added a commit to ckipp01/mill that referenced this issue Dec 22, 2023
Looking at the last change that was made to this code in
com-lihaoyi@65fbd53
it's not clear to me why this line was added where we map everything to
`BspModule` and then filtering the build targets on that which where in
the request. My assumption is that anything that the build client is
requesting to clean _should_ be a valid identifier. If not, then that
originally came from Mill, so I'm unsure why we have this. Before this
change it was causing issues since not everything in `state.rootModules`
was a `BspModule` so you'd get a match exception.

To expand a bit the build targets here in an example `mill-test` (hello
world) project are:

```
BuildTargetIdentifier [
  uri = "file:///Users/<me>/Documents/scala-workspace/mill-test/milltest"
],BuildTargetIdentifier [
  uri = "file:///Users/<me>/Documents/scala-workspace/mill-test/mill-build"
]
```

But when looking into the `state.rootModules` one of them is

```
/Users/<me>/Documents/scala-workspace/mill-test
```

This was the problematic one. I'm not sure if this is just a mapping
issue or not, but the change I made instead just takes the build target
identifies given from the client, does a look up in the
`state.bspModulesById` mapping, and goes with it. This seems to work and
simplifies this unless this is introducing an issue that I don't see.

closes com-lihaoyi#2915
@lefou lefou added this to the 0.11.7 milestone Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants