Skip to content

Remove locale dependent FileSystemException check #21633

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

Merged
merged 1 commit into from
Feb 21, 2025

Conversation

niklasf
Copy link
Contributor

@niklasf niklasf commented Sep 23, 2024

In SourceFile, files that do not exist are expected and related exceptions should be ignored. There are two relevant cases:

scala> java.nio.file.Files.newInputStream(java.nio.file.FileSystems.getDefault().getPath("does-not-exist"))
java.nio.file.NoSuchFileException: does-not-exist

scala> java.nio.file.Files.newInputStream(java.nio.file.FileSystems.getDefault().getPath("regular-file-instead-of-directory/filename"))
java.nio.file.FileSystemException: regular-file-instead-of-directory/filename: Not a directory

Ideally, other I/O errors would be propagated to the caller.

However, there is no reliable way to distinguish them based on the exceptions alone. In particular, the message cannot be checked, because it depends on the operating system and it is localized.

Revert the addition of the check and just accept this.


Resolves the following concrete bug:

  1. Use an operating system that localizes strerror, like Debian.
  2. Check out https://github.com/lichess-org/lila before lichess-org/lila@8610e6f
  3. LANGUAGE=fr sbt compile
  4. ICE with java.nio.file.FileSystemException: lila/src/main/scala/future.scala: N'est pas un dossier (stacktrace)

Not sure how to exercise locale dependent issues in a unit test.


cc @som-snytt in case I misinterpreted 159da44 and distinguishing other I/O errors is not optional.

Fin SourceFile, files that do not exist are expected and related exceptions
should be ignored. There are two relevant cases:

    scala> java.nio.file.Files.newInputStream(java.nio.file.FileSystems.getDefault().getPath("does-not-exist"))
    java.nio.file.NoSuchFileException: does-not-exist

    scala> java.nio.file.Files.newInputStream(java.nio.file.FileSystems.getDefault().getPath("regular-file-instead-of-directory/filename"))
    java.nio.file.FileSystemException: regular-file-instead-of-directory/filename: Not a directory

Ideally, other I/O errors would be propagated to the caller.

However, there is no reliable way to distinguish them based on the
exceptions alone. In particular, the message cannot be checked, because
it depends on the operating system and it is localized.

Revert the addition of the check and just accept this.
@hamzaremmal hamzaremmal merged commit 699e0cb into scala:main Feb 21, 2025
28 checks passed
Copy link
Contributor

@som-snytt som-snytt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the simplest solution.

Probably the previous solution was conservative (if inadequate) because it conceals other problems. If my file doesn't have read permission, it no longer throws AccessDenied.

Error: java.nio.file.AccessDeniedException: /home/**/awkward.scala

Maybe that's the important one? Maybe this is easier to address post-jdk8? Maybe this is easier to address after rewriting the ancient AbstractFile abstraction?

SourceFile is also the wrong level for handling the error. (Pun alert, SoresFile.)

But limping along is better than a partial Anglo- and OS- centric solution. An improved fix can be TODO.

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

Successfully merging this pull request may close these issues.

4 participants