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

Cannot run a script in the root directory #2954

Closed
DavidPerezIngeniero opened this issue Jun 6, 2024 · 4 comments · Fixed by #2988
Closed

Cannot run a script in the root directory #2954

DavidPerezIngeniero opened this issue Jun 6, 2024 · 4 comments · Fixed by #2988
Labels
bug Something isn't working scripting Issues tied to *.sc script inputs.

Comments

@DavidPerezIngeniero
Copy link

Version(s)
Scala-cli vesion 1.3.2

Describe the bug
Run a script with these contents:

//> using dep com.lihaoyi::requests:0.8.3
//> using dep com.lihaoyi::os-lib:0.10.2
//> using dep com.lihaoyi::upickle:3.3.1
//> using dep org.scala-lang.modules::scala-parallel-collections:1.0.4
println("Descargadas dependencias mas usadas")

localted in the root folder with:

scala-cli /myscript.sc

It complains like:

Error: os.PathError$LastOnEmptyPath: empty path has no last segment

When run in any other directory, it works ok as expected.

@DavidPerezIngeniero DavidPerezIngeniero added the bug Something isn't working label Jun 6, 2024
@philwalk
Copy link
Contributor

philwalk commented Jun 7, 2024

The error message is printed by os.Path, and might be a bug there.

@Gedochao
Copy link
Contributor

Any additional details on how to reproduce the problem?
I tried reproducing locally on MacOS (aarch64), but seems to work correctly.

@DavidPerezIngeniero Is it just this particular script, or did you try anything else?
Would a hello world script run into the same issue?

println("Hello")

if not, how about this:

//> using toolkit default
println(os.pwd)

@philwalk
Copy link
Contributor

I was able to reproduce the problem in WSL ubuntu and in Windows. I'm surprised that you don't get the same thing in MacOS.

My hunch (not yet confirmed) is that it's a bug in os-lib, the result of trying to access the last segment of the root Path.

Here's my script. The shebang line is triggering the crash, so it shouldn't matter what the script does (according to my hunch).

#!/usr/bin/env -S scala-cli shebang
println("hello")

Here's the stackdump:

os.PathError$LastOnEmptyPath: empty path has no last segment
  os.PathError$LastOnEmptyPath$.apply(Path.scala:228)
  os.BasePathImpl.last$$anonfun$1(Path.scala:210)
  scala.Option.getOrElse(Option.scala:201)
  os.BasePathImpl.last(Path.scala:210)
  os.BasePathImpl.last$(Path.scala:190)
  os.Path.last(Path.scala:483)
  os.BasePathImpl.baseName(Path.scala:205)
  os.BasePathImpl.baseName$(Path.scala:190)
  os.Path.baseName(Path.scala:483)
  scala.build.input.Inputs$.forValidatedElems(Inputs.scala:155)
  scala.build.input.Inputs$.forNonEmptyArgs(Inputs.scala:414)
  scala.build.input.Inputs$.apply(Inputs.scala:459)
  scala.cli.commands.shared.SharedOptions$.inputs(SharedOptions.scala:697)
  scala.cli.commands.shared.SharedOptions.inputs(SharedOptions.scala:617)
  scala.cli.commands.run.Run$.runCommand(Run.scala:140)
  scala.cli.commands.shebang.Shebang$.runCommand(Shebang.scala:33)
  scala.cli.commands.shebang.Shebang$.runCommand(Shebang.scala:26)
  scala.cli.commands.ScalaCommand.run(ScalaCommand.scala:379)
  scala.cli.commands.ScalaCommand.run(ScalaCommand.scala:361)
  caseapp.core.app.CaseApp.main(CaseApp.scala:157)
  scala.cli.commands.ScalaCommand.main(ScalaCommand.scala:346)
  caseapp.core.app.CommandsEntryPoint.main(CommandsEntryPoint.scala:166)
  scala.cli.ScalaCliCommands.main(ScalaCliCommands.scala:125)
  scala.cli.ScalaCli$.main0(ScalaCli.scala:286)
  scala.cli.ScalaCli$.main(ScalaCli.scala:116)
  scala.cli.ScalaCli.main(ScalaCli.scala)

My hunch: the call to os.Path.baseName fails if the os.Path is root, because "/" has an empty segments array.
I will see if I can verify this.

@philwalk
Copy link
Contributor

philwalk commented Jun 11, 2024

Submitted an os-lib PR: com-lihaoyi/os-lib#277

submitted #2988

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working scripting Issues tied to *.sc script inputs.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants