apache/iceberg · error · RuntimeIOException

Can't create file %s

Error message

Can't create file %s

What it means

ORC's newFileWriter creates the output file via OrcFile.createWriter. If an IOException occurs (unwritable directory, existing blob conflict, permissions, storage outage), it is rethrown as RuntimeIOException with 'Can't create file <path>'.

Source

Thrown at orc/src/main/java/org/apache/iceberg/orc/ORC.java:825

    } catch (IOException ioe) {
      throw new RuntimeIOException(ioe, "Failed to open file: %s", file.location());
    }
  }

  static Writer newFileWriter(
      OutputFile file, OrcFile.WriterOptions options, Map<String, byte[]> metadata) {
    if (file instanceof HadoopOutputFile) {
      options.fileSystem(((HadoopOutputFile) file).getFileSystem());
    } else {
      options.fileSystem(new FileIOFSUtil.OutputFileSystem(file));
    }
    final Path locPath = new Path(file.location());
    final Writer writer;

    try {
      writer = OrcFile.createWriter(locPath, options);
    } catch (IOException ioe) {
      throw new RuntimeIOException(ioe, "Can't create file %s", locPath);
    }

    metadata.forEach((key, value) -> writer.addUserMetadata(key, ByteBuffer.wrap(value)));

    return writer;
  }
}

View on GitHub (pinned to 86d9c8fc54)

Solutions

  1. Verify the output location/URI and that the parent directory/bucket exists and is writable
  2. Check storage credentials and permissions for writes
  3. Retry the write if the underlying storage error was transient
  4. Validate FileIO configuration (fs defaults, region, endpoint)

Example fix

// before
String loc = "hdfs://old-nn/warehouse/table/data/file.orc"; // stale NameNode
// after
String loc = table.locationProvider().newDataLocation(spec, partition, filename); // derive from table config
Defensive patterns

Strategy: try-catch

Validate before calling

OutputFile out = io.newOutputFile(target);
// verify location writable with a small probe where supported, e.g.
if (!target.startsWith(table.location())) throw new IllegalArgumentException("Write outside table location");

Try / catch

try {
  return OrcFileAppenderFactory.create(out, options, metadata);
} catch (RuntimeIOException e) {
  if (e.getMessage().startsWith("Can't create file")) {
    log.error("Cannot create ORC output {}: {}", out.location(), e.getCause());
    throw e;
  } throw e;
}

Prevention

When it happens

Trigger: Writing ORC data files when the target OutputFile cannot be created: bad output path/URI, insufficient permissions, storage quota/bucket issues, transient S3/HDFS errors.

Common situations: Misconfigured write.location or warehouse path; S3 bucket missing or credentials lacking PutObject; HDFS NameNode unreachable; disk full on local writes.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12). Data as JSON: /api/errors/0b3a0e4b2b5b0c96. Report an issue: GitHub.