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
550 stars 129 forks source link

On Windows 10, scala-cli fails after installation with "download error" #2024

Closed oreineke closed 1 year ago

oreineke commented 1 year ago

Version(s) (on Windows 10)

>scala-cli version
Scala CLI version: 1.0.0-RC1
Scala version (default): 3.2.2

Describe the bug On Windows 10, scala-cli fails after installation with the following error:

>scala-cli

Error: java.lang.Exception: java.lang.Exception: Error while getting https://github.com/coursier/jvm-index/raw/master/index.json: download error: Caught java.net.ConnectException (Connection refused: connect) while downloading https://github.com/coursier/jvm-index/raw/master/index.json
For more details, please see 'C:\Users\or\.scala-build\stacktraces\1680891948-3708010854185332807.log'

The log file states:

java.lang.Exception: java.lang.Exception: Error while getting https://github.com/coursier/jvm-index/raw/master/index.json: download error: Caught java.net.ConnectException (Connection refused: connect) while downloading https://github.com/coursier/jvm-index/raw/master/index.json
  scala.cli.commands.shared.SharedOptions.$anonfun$28(SharedOptions.scala:479)
  coursier.cache.CacheLogger.use(CacheLogger.scala:49)
  coursier.cache.CacheLogger.use$(CacheLogger.scala:47)
  coursier.cache.loggers.RefreshLogger.use(RefreshLogger.scala:209)
  scala.cli.commands.shared.SharedOptions.downloadJvm(SharedOptions.scala:481)
  scala.cli.commands.shared.SharedOptions.defaultJvmCmd$lzyINIT1$1(SharedOptions.scala:492)
  scala.cli.commands.shared.SharedOptions.defaultJvmCmd$1(SharedOptions.scala:492)
  scala.cli.commands.shared.SharedOptions.$anonfun$30$$anonfun$1(SharedOptions.scala:497)
  scala.Option.map(Option.scala:242)
  scala.cli.commands.shared.SharedOptions.$anonfun$30(SharedOptions.scala:498)
  scala.Option.orElse(Option.scala:477)
  scala.cli.commands.shared.SharedOptions.bloopRifleConfig$$anonfun$1(SharedOptions.scala:499)
  scala.build.EitherCps$Helper.apply(EitherCps.scala:19)
  scala.cli.commands.shared.SharedOptions.bloopRifleConfig(SharedOptions.scala:509)
  scala.cli.commands.shared.SharedOptions.compilerMaker$$anonfun$1(SharedOptions.scala:519)
  scala.build.EitherCps$Helper.apply(EitherCps.scala:19)
  scala.cli.commands.shared.SharedOptions.compilerMaker(SharedOptions.scala:525)
  scala.cli.commands.repl.Repl$.runCommand(Repl.scala:112)
  scala.cli.commands.default.Default.runCommand(Default.scala:61)
  scala.cli.commands.default.Default.runCommand(Default.scala:48)
  scala.cli.commands.ScalaCommand.run(ScalaCommand.scala:365)
  scala.cli.commands.ScalaCommand.run(ScalaCommand.scala:352)
  caseapp.core.app.CaseApp.main(CaseApp.scala:150)
  scala.cli.commands.ScalaCommand.main(ScalaCommand.scala:337)
  caseapp.core.app.CommandsEntryPoint.main(CommandsEntryPoint.scala:120)
  scala.cli.ScalaCliCommands.main(ScalaCliCommands.scala:124)
  scala.cli.ScalaCli$.main0(ScalaCli.scala:203)
  scala.cli.ScalaCli$.main(ScalaCli.scala:107)
  scala.cli.ScalaCli.main(ScalaCli.scala)
java.lang.Exception: Error while getting https://github.com/coursier/jvm-index/raw/master/index.json: download error: Caught java.net.ConnectException (Connection refused: connect) while downloading https://github.com/coursier/jvm-index/raw/master/index.json
  coursier.jvm.JvmIndex$.$anonfun$load$5(JvmIndex.scala:142)
  coursier.jvm.JvmIndex$.$anonfun$load$5$adapted(JvmIndex.scala:140)
  coursier.util.Task$.$anonfun$flatMap$extension$1(Task.scala:14)
  coursier.util.Task$.$anonfun$flatMap$extension$1$adapted(Task.scala:14)
  coursier.util.Task$.wrap(Task.scala:82)
  coursier.util.Task$.$anonfun$flatMap$2(Task.scala:14)
  scala.concurrent.impl.Promise$Transformation.run(Promise.scala:470)
  java.base@17.0.5/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
  java.base@17.0.5/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
  java.base@17.0.5/java.lang.Thread.run(Thread.java:833)
  com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:775)
  com.oracle.svm.core.windows.WindowsPlatformThreads.osThreadStartRoutine(WindowsPlatformThreads.java:178)

Using curl https://github.com/coursier/jvm-index/raw/master/index.json, will return a HTTP 302 redirect:

>curl -v https://github.com/coursier/jvm-index/raw/master/index.json
*   Trying 140.82.121.3:443...
* Connected to github.com (140.82.121.3) port 443 (#0)
* schannel: disabled automatic use of client certificate
* ALPN: offers http/1.1
* ALPN: server accepted http/1.1
> GET /coursier/jvm-index/raw/master/index.json HTTP/1.1
> Host: github.com
> User-Agent: curl/7.83.1
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 302 Found
< Server: GitHub.com
< Date: Fri, 07 Apr 2023 18:37:52 GMT
< Content-Type: text/html; charset=utf-8
< Vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, Accept-Encoding, Accept, X-Requested-With
< Access-Control-Allow-Origin: https://render.githubusercontent.com
< Location: https://raw.githubusercontent.com/coursier/jvm-index/master/index.json
< Cache-Control: no-cache
< Strict-Transport-Security: max-age=31536000; includeSubdomains; preload
< X-Frame-Options: deny
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 0
< Referrer-Policy: no-referrer-when-downgrade
< Content-Security-Policy: default-src 'none'; base-uri 'self'; block-all-mixed-content; child-src github.com/assets-cdn/worker/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com objects-origin.githubusercontent.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com cdn.optimizely.com logx.optimizely.com/v1/events *.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ wss://*.actions.githubusercontent.com online.visualstudio.com/api/v1/locations github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com objects-origin.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; worker-src github.com/assets-cdn/worker/ gist.github.com/assets-cdn/worker/
< Content-Length: 0
< X-GitHub-Request-Id: C27E:58A5:1BF48CF:1C5CD95:6430631D
<
* Connection #0 to host github.com left intact

Running curl on the redirect target location https://raw.githubusercontent.com/coursier/jvm-index/master/index.json, will in fact download the expected index.json file.

Therefore, could this be caused by scala-cli not correctly handling the HTTP 302 redirect on Windows 10?

To Reproduce Happens on every subsequent run, in CMD, Powershell, Git-Bash, with Firewall on or off.

scala-cli works fine on the same machine in WSL2 (Ubuntu 22.04).

Expected behaviour scala-cli should download its dependencies during the first run.

oreineke commented 1 year ago

This turned out to have been caused be an invalid root certificate in Windows. After removing it using the Windows certmgr, installation completed as expected.