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

os.root.baseName throws an exception #276

Open
philwalk opened this issue Jun 11, 2024 · 1 comment
Open

os.root.baseName throws an exception #276

philwalk opened this issue Jun 11, 2024 · 1 comment

Comments

@philwalk
Copy link
Contributor

philwalk commented Jun 11, 2024

A new scala-cli bug is caused by os.root.baseName being an empty string throwing an exception.

VirtusLab/scala-cli#2954
If a scala-cli script resides in the root directory, it crashes with an error message:

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

Although this could be avoided in client code, it would require any os.Path object to be tested before referencing baseName.

One way to avoid the exception would be to redefine os.root.baseName as the empty String. However, the jvm defines the empty String as pwd, so if os.root.baseName is also the empty String, that would make it equal to pwd, which is a problem.

Shell environments (mostly) treat the root directory as its own parent, which is much easier to work with. For example, /usr/bin/basename takes this approach. The expression basename / resolves to /.

Defining os.root.baseName as s"$driveRoot/" resolves the scala-cli bug.

This is the approach taken by PR #277

@philwalk
Copy link
Contributor Author

Clarification: the original symptom for the scala-cli bug was a LastOnEmptyPath error.

@philwalk philwalk changed the title os.root.baseName is an empty String, causing it to be equivalent to cwd in some contexts. os.root.baseName throws an exception Jun 14, 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

No branches or pull requests

1 participant