apache/dolphinscheduler · error · RuntimeException
Error writing file:
Error message
Error writing file:
What it means
The private FileUtils.writeStringToFile writes UTF-8 content to the given file with an optional StandardOpenOption. An IOException is wrapped in RuntimeException('Error writing file: <abs path>'). It is the low-level sink for all Flink SQL script writes, so any write failure surfaces here.
Source
Thrown at dolphinscheduler-task-plugin/dolphinscheduler-task-flink/src/main/java/org/apache/dolphinscheduler/plugin/task/flink/FileUtils.java:105
Files.createFile(path, attr);
}
if (StringUtils.isNotEmpty(script)) {
String replacedScript = script.replaceAll("\\r\\n", "\n");
FileUtils.writeStringToFile(scriptFile, replacedScript, StandardOpenOption.APPEND);
}
} catch (IOException e) {
throw new RuntimeException("Generate flink SQL script error", e);
}
}
private static void writeStringToFile(File file, String content, StandardOpenOption standardOpenOption) {
try {
log.info("Writing content: " + content);
log.info("To file: " + file.getAbsolutePath());
Files.write(file.getAbsoluteFile().toPath(), content.getBytes(StandardCharsets.UTF_8), standardOpenOption);
} catch (IOException e) {
throw new RuntimeException("Error writing file: " + file.getAbsoluteFile(), e);
}
}
}
View on GitHub (pinned to 02eac45a1b)
Solutions
- Free disk space / check quotas on the worker
- Confirm the worker user has write permission on the file and parent directory
- Avoid concurrent tasks sharing one script path; use unique paths per execution
- Inspect the wrapped cause (AccessDeniedException vs FileSystemException) to target the fix
Example fix
// before Files.write(file.getAbsoluteFile().toPath(), content.getBytes(StandardCharsets.UTF_8), standardOpenOption); // after Path target = file.getAbsoluteFile().toPath(); Files.createDirectories(target.getParent()); Files.write(target, content.getBytes(StandardCharsets.UTF_8), standardOpenOption);
Defensive patterns
Strategy: try-catch
Validate before calling
File f = new File(path);
if (!f.getParentFile().canWrite()) throw new IllegalStateException("no write permission on " + f.getParent());
if (f.getUsableSpace() < 1_000_000) throw new IllegalStateException("insufficient disk space"); Try / catch
try {
task.handle(null);
} catch (RuntimeException e) {
Throwable cause = e.getCause();
if (cause instanceof AccessDeniedException) { /* fix permissions */ }
else if (cause instanceof FileSystemException) { /* check disk/mount */ }
throw e;
} Prevention
- Monitor disk usage on workers
- Create parent directories before writing
- Use per-execution unique file names
- Confirm open options (CREATE+APPEND vs TRUNCATE) match the file's state
When it happens
Trigger: Files.write() throws IOException: NoSpaceLeftOnException, AccessDeniedException, NoSuchFileException (parent dir removed), or invalid open option combination.
Common situations: Disk full; directory permissions; the script file deleted between creation and write by a cleanup job; concurrent tasks writing the same file with conflicting open options.
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
- Generate flink SQL script error
- cancel application error
- Flink Script file exists in path: %s before creation and can
- Calculate checksum error.
- Error reading file: ${filePath}
AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06).
Data as JSON: /api/errors/4fbc80b075acd991.
Report an issue: GitHub.