{"record":{"id":"d7a9b3fed7449c1c","repo":"apache/flink","slug":"output-path-could-not-be-initialized-canceli","errorCode":null,"errorMessage":"Output path '{}' could not be initialized. Canceling task...","messagePattern":"Output path '(.+?)' could not be initialized\\. Canceling task\\.\\.\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/io/FileOutputFormat.java","lineNumber":221,"sourceCode":"\n        Path p = this.outputFilePath;\n        if (p == null) {\n            throw new IOException(\"The file path is null.\");\n        }\n\n        final FileSystem fs = p.getFileSystem();\n\n        // if this is a local file system, we need to initialize the local output directory here\n        if (!fs.isDistributedFS()) {\n\n            if (numTasks == 1 && outputDirectoryMode == OutputDirectoryMode.PARONLY) {\n                // output should go to a single file\n\n                // prepare local output path. checks for write mode and removes existing files in\n                // case of OVERWRITE mode\n                if (!fs.initOutPathLocalFS(p, writeMode, false)) {\n                    // output preparation failed! Cancel task.\n                    throw new IOException(\n                            \"Output path '\"\n                                    + p.toString()\n                                    + \"' could not be initialized. Canceling task...\");\n                }\n            } else {\n                // numTasks > 1 || outDirMode == OutputDirectoryMode.ALWAYS\n\n                if (!fs.initOutPathLocalFS(p, writeMode, true)) {\n                    // output preparation failed! Cancel task.\n                    throw new IOException(\n                            \"Output directory '\"\n                                    + p.toString()\n                                    + \"' could not be created. Canceling task...\");\n                }\n            }\n        }\n\n        // Suffix the path with the parallel instance index, if needed","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/io/FileOutputFormat.java#L203-L239","documentation":"Thrown by FileOutputFormat.open on a LOCAL (non-distributed) filesystem when the output is non-parallel single-file mode (numTasks==1, OutputDirectoryMode.PARONLY) and fs.initOutPathLocalFS(path, writeMode, false) returns false. A false return means the path could not be prepared (e.g., target exists and writeMode is NO_OVERWRITE, or a directory exists where a file is expected).","triggerScenarios":"Writing to a local file path that already exists while WriteMode.NO_OVERWRITE is set; the target path is a directory but single-file mode expects a file; local filesystem permission to create/truncate the file is missing.","commonSituations":"Local/IDE runs writing to an existing output file without OVERWRITE; re-running a job whose previous output file still exists; pointing the sink at a path occupied by a directory.","solutions":["Set WriteMode.OVERWRITE if reruns should replace the file: format.setWriteMode(WriteMode.OVERWRITE).","Delete the existing local file before running, or write to a fresh path.","If a directory genuinely exists at that path, choose a file path instead, or switch to OutputDirectoryMode.ALWAYS."],"exampleFix":"// before\nFileOutputFormat out = new FileOutputFormat(new Path(\"file:///tmp/result\"));\n// rerun → existing file, NO_OVERWRITE → init fails\n\n// after\nout.setWriteMode(WriteMode.OVERWRITE);","handlingStrategy":"validation","validationCode":"// Clear or allow overwrite of an existing local target\nPath localOut = new Path(\"file:///tmp/result\");\nif (localOut.getFileSystem().exists(localOut)) {\n    localOut.getFileSystem().delete(localOut, false);\n}\n// or set overwrite\nformat.setWriteMode(WriteMode.OVERWRITE);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use WriteMode.OVERWRITE for rerunnable local jobs.","Delete the existing local file before running if NO_OVERWRITE.","Avoid pointing a single-file sink at a path that is already a directory."],"tags":["flink","file-output","local-fs","write-mode","overwrite"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}