eclipse-vertx/vert.x · error · FileSystemException

Failed to read ${path}

Error message

Failed to read ${path}

What it means

Wrapped error in readFileInternal: opening the resolved path with FileChannel or reading its content threw an IOException. The message names the read operation and the raw path; the real reason (permission denied, file vanished, lock) is in the cause chain.

Source

Thrown at vertx-core/src/main/java/io/vertx/core/file/impl/FileSystemImpl.java:867

  private BlockingAction<Buffer> readFileInternal(String path) {
    Objects.requireNonNull(path);
    return new BlockingAction<Buffer>() {
      public Buffer perform() {
        try {
          Path target = resolveFile(path).toPath();
          try (FileChannel fc = FileChannel.open(target, StandardOpenOption.READ)) {
            long size = fc.size();
            if (size > (long) Integer.MAX_VALUE) {
              // Throwing OOM as Files#readAllLines would in this case
              throw new OutOfMemoryError("File is too big");
            }
            int len = (int) size;
            BufferInternal res = BufferInternal.buffer(len);
            res.unwrap().writeBytes(fc, 0, len);
            return res;
          }
        } catch (IOException e) {
          throw new FileSystemException(getFileAccessErrorMessage("read", path), e);
        }
      }
    };
  }

  private BlockingAction<Void> writeFileInternal(String path, Buffer data) {
    Objects.requireNonNull(path);
    Objects.requireNonNull(data);
    return new BlockingAction<Void>() {
      public Void perform() {
        try {
          Path target = resolveFile(path).toPath();
          Files.write(target, data.getBytes());
          return null;
        } catch (IOException e) {
          throw new FileSystemException(getFileAccessErrorMessage("write", path), e);
        }
      }

View on GitHub (pinned to fb308bd8c3)

Solutions

  1. Inspect the cause for the concrete I/O failure
  2. Verify the file exists and is readable
  3. Retry transient failures such as concurrent moves

Example fix

// before
vertx.fileSystem().readFile("config.yaml");
// after
vertx.fileSystem().exists("config.yaml")
  .onSuccess(exists -> { if (!exists) throw ...; })
  .compose(v -> vertx.fileSystem().readFile("config.yaml"));
Defensive patterns

Strategy: try-catch

Validate before calling

if (!vertx.fileSystem().existsBlocking(path)) {
  throw new IllegalArgumentException("File does not exist: " + path);
}

Try / catch

try {
  Buffer buf = fs.readFileBlocking(path);
} catch (FileSystemException e) {
  logger.error("Failed to read {}: {}", path, e.getCause());
  // handle missing file / permission error
}

Prevention

When it happens

Trigger: Calling FileSystem.readFile(path) when the file does not exist, is a directory, permission is denied, or an I/O error occurs mid-read.

Common situations: Wrong working directory at runtime, file not packaged/deployed with the app, permission denied under a restricted service account, or reading a path that is actually a directory.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of eclipse-vertx/vert.x@fb308bd8c3 (2026-09-06). Data as JSON: /api/errors/444a923dc1ae54c2. Report an issue: GitHub.