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

Project export fails with java.nio.file.FileAlreadyExistsException with file and lib import #2015

Closed
carlosedp opened this issue Apr 6, 2023 · 2 comments · Fixed by #2098
Assignees
Labels
bug Something isn't working

Comments

@carlosedp
Copy link
Contributor

carlosedp commented Apr 6, 2023

Version(s)

Scala CLI version: 1.0.0-RC1
Scala version (default): 3.2.2

Describe the bug

In a project which one file with main method imports another file which imports a lib, exporting to a mill or sbt project fails:

❯ scli export --mill --project testrepro -o testrepro .
The 'export' sub-command is experimental.
Please bear in mind that non-ideal user experience should be expected.
If you encounter any bugs or have feedback to share, make sure to reach out to the maintenance team at https://github.com/VirtusLab/scala-cli
Exporting to a mill project...
Error: java.nio.file.FileAlreadyExistsException: /Users/cdepaula/repos/scala-playground/zio/test/testrepro/testrepro/src/Helpers.scala
For more details, please see '/Users/cdepaula/repos/scala-playground/zio/test/.scala-build/stacktraces/1680786544-2919053400650754756.log'

The project is:

❯ tree
[ 564]  ./
├── [ 180]  Helpers.scala
└── [ 160]  sample1.scala

  340 used in 1 directory, 2 files

❯ cat *
────────────────────────────────────────────────────────────────────────────────────────────────────
File: Helpers.scala
Size: 180 B
────────────────────────────────────────────────────────────────────────────────────────────────────
//> using scala "3.3.0-RC3"
//> using option "-source:future"
//> using lib "dev.zio::zio:2.0.10"

package testrepro

import zio.*

def printMy(msg: String): Unit =
  println(msg)
────────────────────────────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────────────────────────────
File: sample1.scala
Size: 160 B
────────────────────────────────────────────────────────────────────────────────────────────────────
//> using scala "3.3.0-RC3"

//> using file "Helpers.scala"
//> using option "-source:future"

package testrepro

@main
def main() =
  printMy("Hello, world!")
────────────────────────────────────────────────────────────────────────────────────────────────────

If I comment (remove) the using lib and import from Helpers.scala, it exports successfully or if I remove the sample 1 file, it also exports successfully.

Expected behaviour
Be able to export rojects that use both libs and local files.

The stacktrace mentioned shows:

❯ cat /Users/cdepaula/repos/scala-playground/zio/test/.scala-build/stacktraces/1680786544-2919053400650754756.log
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
File: /Users/cdepaula/repos/scala-playground/zio/test/.scala-build/stacktraces/1680786544-2919053400650754756.log
Size: 1.6 KB
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
java.nio.file.FileAlreadyExistsException: /Users/cdepaula/repos/scala-playground/zio/test/testrepro/testrepro/src/Helpers.scala
  java.base@17.0.5/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:218)
  java.base@17.0.5/java.nio.file.Files.newByteChannel(Files.java:380)
  os.write$.write(ReadWriteOps.scala:64)
  os.write$.apply(ReadWriteOps.scala:77)
  scala.cli.exportCmd.MillProject.writeTo$$anonfun$5(MillProject.scala:143)
  scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
  scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
  scala.collection.IterableOnceOps.foreach(IterableOnce.scala:575)
  scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:573)
  scala.collection.AbstractIterable.foreach(Iterable.scala:933)
  scala.collection.IterableOps$WithFilter.foreach(Iterable.scala:903)
  scala.cli.exportCmd.MillProject.writeTo(MillProject.scala:144)
  scala.cli.commands.export0.Export$.runCommand(Export.scala:195)
  scala.cli.commands.export0.Export$.runCommand(Export.scala:104)
  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)
@carlosedp carlosedp added the bug Something isn't working label Apr 6, 2023
@Gedochao Gedochao self-assigned this May 5, 2023
@Gedochao
Copy link
Contributor

Gedochao commented May 8, 2023

I believe the reason behind the error is that the Helpers.scala file in the example is in fact passed twice: once through the using file directive and once from the command line with ..
So a quick workaround would be to just export it like this:

scala-cli export --mill --project testrepro -o testrepro sample1.scala

Now, while passing sources twice like this isn't advisable, it still shouldn't break, so I added a fix in #2098

@carlosedp
Copy link
Contributor Author

Thanks for the fix Piotr!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants