{"record":{"id":"4fbc80b075acd991","repo":"apache/dolphinscheduler","slug":"error-writing-file","errorCode":null,"errorMessage":"Error writing file: ","messagePattern":"Error writing file: ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-task-plugin/dolphinscheduler-task-flink/src/main/java/org/apache/dolphinscheduler/plugin/task/flink/FileUtils.java","lineNumber":105,"sourceCode":"                Files.createFile(path, attr);\n            }\n\n            if (StringUtils.isNotEmpty(script)) {\n                String replacedScript = script.replaceAll(\"\\\\r\\\\n\", \"\\n\");\n                FileUtils.writeStringToFile(scriptFile, replacedScript, StandardOpenOption.APPEND);\n            }\n        } catch (IOException e) {\n            throw new RuntimeException(\"Generate flink SQL script error\", e);\n        }\n    }\n\n    private static void writeStringToFile(File file, String content, StandardOpenOption standardOpenOption) {\n        try {\n            log.info(\"Writing content: \" + content);\n            log.info(\"To file: \" + file.getAbsolutePath());\n            Files.write(file.getAbsoluteFile().toPath(), content.getBytes(StandardCharsets.UTF_8), standardOpenOption);\n        } catch (IOException e) {\n            throw new RuntimeException(\"Error writing file: \" + file.getAbsoluteFile(), e);\n        }\n    }\n}\n","sourceCodeStart":87,"sourceCodeEnd":109,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-task-plugin/dolphinscheduler-task-flink/src/main/java/org/apache/dolphinscheduler/plugin/task/flink/FileUtils.java#L87-L109","documentation":"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.","triggerScenarios":"Files.write() throws IOException: NoSpaceLeftOnException, AccessDeniedException, NoSuchFileException (parent dir removed), or invalid open option combination.","commonSituations":"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.","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"],"exampleFix":"// before\nFiles.write(file.getAbsoluteFile().toPath(), content.getBytes(StandardCharsets.UTF_8), standardOpenOption);\n// after\nPath target = file.getAbsoluteFile().toPath();\nFiles.createDirectories(target.getParent());\nFiles.write(target, content.getBytes(StandardCharsets.UTF_8), standardOpenOption);","handlingStrategy":"try-catch","validationCode":"File f = new File(path);\nif (!f.getParentFile().canWrite()) throw new IllegalStateException(\"no write permission on \" + f.getParent());\nif (f.getUsableSpace() < 1_000_000) throw new IllegalStateException(\"insufficient disk space\");","typeGuard":null,"tryCatchPattern":"try {\n    task.handle(null);\n} catch (RuntimeException e) {\n    Throwable cause = e.getCause();\n    if (cause instanceof AccessDeniedException) { /* fix permissions */ }\n    else if (cause instanceof FileSystemException) { /* check disk/mount */ }\n    throw e;\n}","preventionTips":["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"],"tags":["file-io","write","ioexception","flink"],"backgroundTag":"file-write-failed","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}