{"record":{"id":"9e90adc7b08d2d3b","repo":"apache/hadoop","slug":"failed-to-create-output-dir","errorCode":null,"errorMessage":"Failed to create output dir: {}","messagePattern":"Failed to create output dir: (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-tools/hadoop-fs2img/src/main/java/org/apache/hadoop/hdfs/server/namenode/ImageWriter.java","lineNumber":126,"sourceCode":"      .setLayoutVersion(LAYOUT_VERSION);\n\n  private final String blockPoolID;\n\n  public static Options defaults() {\n    return new Options();\n  }\n\n  @SuppressWarnings(\"unchecked\")\n  public ImageWriter(Options opts) throws IOException {\n    final OutputStream out;\n    if (null == opts.outStream) {\n      FileSystem fs = opts.outdir.getFileSystem(opts.getConf());\n      outfs = (fs instanceof LocalFileSystem)\n          ? ((LocalFileSystem)fs).getRaw()\n          : fs;\n      Path tmp = opts.outdir;\n      if (!outfs.mkdirs(tmp)) {\n        throw new IOException(\"Failed to create output dir: \" + tmp);\n      }\n      try (NNStorage stor = new NNStorage(opts.getConf(),\n          Arrays.asList(tmp.toUri()), Arrays.asList(tmp.toUri()))) {\n        NamespaceInfo info = NNStorage.newNamespaceInfo();\n        if (info.getLayoutVersion() != LAYOUT_VERSION) {\n          throw new IllegalStateException(\"Incompatible layout \" +\n              info.getLayoutVersion() + \" (expected \" + LAYOUT_VERSION + \")\");\n        }\n        // set the cluster id, if given\n        if (opts.clusterID.length() > 0) {\n          info.setClusterID(opts.clusterID);\n        }\n        // if block pool id is given\n        if (opts.blockPoolID.length() > 0) {\n          info.setBlockPoolID(opts.blockPoolID);\n        }\n\n        stor.format(info);","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-tools/hadoop-fs2img/src/main/java/org/apache/hadoop/hdfs/server/namenode/ImageWriter.java#L108-L144","documentation":"ImageWriter's constructor creates the output directory (opts.outdir, set by -o) before writing the generated fsimage; when outfs.mkdirs(tmp) returns false rather than throwing, it becomes IOException('Failed to create output dir: <path>'). A false return typically means the target exists as a regular file, a parent is missing or unwritable, or the URI scheme resolved to a filesystem that cannot create the path.","triggerScenarios":"Passing -o with a path occupied by an existing file; running without write permission on the output parent directory; a scheme in the output URI that maps to a read-only or unavailable FileSystem.","commonSituations":"A previous run left a file where the directory should be; output directed to a protected location (e.g. under /var without root); copy-pasted -o value with a typo'd scheme.","solutions":["Ensure the -o path does not already exist as a file; delete or rename the conflicting file, or pick another directory.","Check write permission on the parent directory for the user running fs2img.","Use an explicit, scheme-correct URI for -o (file:///abs/path for local, hdfs://ns/path for HDFS)."],"exampleFix":"# before\ntouch /img && hadoop fs2img -o file:///img /data\n\n# after\nrm -f /img && hadoop fs2img -o file:///img /data","handlingStrategy":"validation","validationCode":"Path outdir = new Path(\"file:///img\");\nFileSystem fs = outdir.getFileSystem(conf);\nif (fs.exists(outdir) && !fs.getFileStatus(outdir).isDirectory()) {\n  throw new IllegalStateException(outdir + \" exists as a file; remove it before fs2img\");\n}\nif (!fs.exists(outdir) && !fs.mkdirs(outdir)) {\n  throw new IllegalStateException(\"cannot create \" + outdir + \"; check parent permissions\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  new ImageWriter(opts);\n} catch (IOException e) {\n  if (e.getMessage().startsWith(\"Failed to create output dir\")) {\n    // fix the -o path: conflicting file or unwritable parent, then retry\n  }\n}","preventionTips":["Pre-check the -o path: absent or an existing directory, and parent writable.","Use explicit schemes (file:/// or hdfs://) in -o to avoid surprise resolution."],"tags":["fs2img","image-writer","mkdir-failed","output-path","permissions"],"backgroundTag":"mkdir-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}