Skip to content

Commit bc1a421

Browse files
committed
[GR-48699] standalone module - VirtualFileSystem.java: adjust thrown IOException (and error message) when file is not found or not a file.
PullRequest: graalpython/2979
2 parents a9f82a8 + 6f65755 commit bc1a421

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

graalpython/lib-graalpython/modules/standalone/templates/VirtualFileSystem.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
import java.io.BufferedReader;
4444
import java.io.ByteArrayOutputStream;
45+
import java.io.FileNotFoundException;
4546
import java.io.IOException;
4647
import java.io.InputStream;
4748
import java.io.InputStreamReader;
@@ -53,6 +54,7 @@
5354
import java.nio.file.DirectoryStream;
5455
import java.nio.file.FileVisitResult;
5556
import java.nio.file.Files;
57+
import java.nio.file.FileSystemException;
5658
import java.nio.file.LinkOption;
5759
import java.nio.file.NotDirectoryException;
5860
import java.nio.file.OpenOption;
@@ -461,10 +463,11 @@ public SeekableByteChannel newByteChannel(Path path, Set<? extends OpenOption> o
461463
if (options.isEmpty() || (options.size() == 1 && options.contains(StandardOpenOption.READ))) {
462464
final Entry e = file(path);
463465
if (e == null) {
464-
throw new IOException("no such file");
466+
throw new FileNotFoundException("No such file or directory");
465467
}
466468
if (!e.isFile) {
467-
throw new IOException("is a directory");
469+
// this constructor is used since we rely on the error message to convert to the appropriate python error
470+
throw new FileSystemException(path.toString(), null, "Is a directory");
468471
}
469472
return new SeekableByteChannel() {
470473
int position = 0;

0 commit comments

Comments
 (0)