VirtusLab / scala-cli

Scala CLI is a command-line tool to interact with the Scala language. It lets you compile, run, test, and package your Scala code (and more!)
https://scala-cli.virtuslab.org
Apache License 2.0
551 stars 129 forks source link

Improve the error message for when coursier cannot fetch a JVM for Bloop #3146

Open Gedochao opened 2 months ago

Gedochao commented 2 months ago

Is your feature request related to a problem? Please describe. On systems for which there is no Java 17+ listing in Coursier's jvm-index, if the JVM isn't provided on Scala CLI startup (i.e. via an environment variable), the error we are printing seemingly coming straight from Coursier) is quite cryptic, and it's not indicating what the user should do in any way. OpenBSD is an example of such an OS.

scala $ env JAVA_HOME=/usr/local/jdk-1.8.0 scala 
Error: java.lang.Exception: Unrecognized OS: openbsd
For more details, please see '/usr/ports/lang/scala/.scala-build/stacktraces/1725217762-8871160887746307735.log'
scala $ cat /usr/ports/lang/scala/.scala-build/stacktraces/1725217762-8871160887746307735.log
java.lang.Exception: Unrecognized OS: openbsd
  coursier.jvm.JvmIndex$.defaultOs(JvmIndex.scala:173)
  scala.build.internal.OsLibc$.jvmIndexOs$lzyINIT1(OsLibc.scala:59)
  scala.build.internal.OsLibc$.jvmIndexOs(OsLibc.scala:58)
  scala.cli.javaLauncher.JavaLauncherCli$.runAndExit(JavaLauncherCli.scala:22)
  scala.cli.ScalaCli$.main0(ScalaCli.scala:251)
  scala.cli.ScalaCli$.main(ScalaCli.scala:117)
  scala.cli.ScalaCli.main(ScalaCli.scala)

Describe the solution you'd like We need a better error message, optimally explaining to the user what he could do to make Scala CLI work. The workaround of using --server=false should also be suggested.

Describe alternatives you've considered We could try to improve the jvm-index system coverage, but that's tricky and there's always some niche OS that we won't be able to cover and its (power) users would still have to set up the JVM themselves.

Additional context Extracted out of: