{"record":{"id":"136a28e9590ccba0","repo":"apple/pkl","slug":"output-path-outputdir-exists-and-is-not-a-direc","errorCode":null,"errorMessage":"Output path `$outputDir` exists and is not a directory.","messagePattern":"Output path `\\$outputDir` exists and is not a directory\\.","errorType":"exception","errorClass":"CliException","httpStatus":null,"severity":"error","filePath":"pkl-cli/src/main/kotlin/org/pkl/cli/CliCommandRunner.kt","lineNumber":116,"sourceCode":"  }\n\n  /**\n   * Renders the command's `output.files`, writing each entry as a file.\n   *\n   * File paths are written to the standard error stream.\n   *\n   * Unlike CliEvaluator, command outputs write relative to --working-dir and may write files\n   * anywhere in the filesystem. This is intentionally less sandboxed than `pkl eval` and directly\n   * targets the capabilities of CLI tools written in general purpose languages. Pkl commands should\n   * therefore be treated as untrusted code the way that any other CLI tool would be.\n   */\n  fun writeMultipleFileOutput(outputFiles: Map<String, FileOutput>) {\n    if (outputFiles.isEmpty()) return\n\n    val writtenFiles = mutableMapOf<Path, String>()\n    val outputDir = options.normalizedWorkingDir\n    if (outputDir.exists() && !outputDir.isDirectory()) {\n      throw CliException(\"Output path `$outputDir` exists and is not a directory.\")\n    }\n    for ((pathSpec, fileOutput) in outputFiles) {\n      checkPathSpec(pathSpec)\n      val resolvedPath = outputDir.resolve(pathSpec).normalize()\n      val realPath = if (resolvedPath.exists()) resolvedPath.toRealPath() else resolvedPath\n      val previousOutput = writtenFiles[realPath]\n      if (previousOutput != null) {\n        throw CliException(\n          \"Output file conflict: `output.files` entries `\\\"${previousOutput}\\\"` and `\\\"$pathSpec\\\"` resolve to the same file path `$realPath`.\"\n        )\n      }\n      if (realPath.isDirectory()) {\n        throw CliException(\n          \"Output file conflict: `output.files` entry `\\\"$pathSpec\\\"` resolves to file path `$realPath`, which is a directory.\"\n        )\n      }\n      writtenFiles[realPath] = pathSpec\n      realPath.createParentDirectories()","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-cli/src/main/kotlin/org/pkl/cli/CliCommandRunner.kt#L98-L134","documentation":"Before writing multiple-file output, CliCommandRunner.writeMultipleFileOutput verifies that the working-directory-derived output path, if it already exists, is a directory. This error means the target output location exists as a regular file (or other non-directory), so per-file outputs cannot be written beneath it.","triggerScenarios":"Running a pkl command with multiple-file output (output.files) while options.normalizedWorkingDir points at an existing regular file — e.g. a stale file created by a previous single-file-output run at the same path.","commonSituations":"Switching from single-file output to multiple-file output without removing the old output file; a script that created a file where a directory is expected; wrong --output-path or working directory flag.","solutions":["Delete or rename the existing file at the output path so the tool can create a directory there.","Point the output path/working dir at an empty directory instead.","If the file is a previous single-file output you still need, move it elsewhere before re-running.","Check the path in your script/CI config — it may reference a file rather than a directory."],"exampleFix":"# before\n$ pkl eval -m out ...   # where `out` is an existing file\nrm out\n# after\n$ mkdir -p out && pkl eval -m out ...","handlingStrategy":"validation","validationCode":"import java.nio.file.*\nval p = Path.of(outputPath)\nrequire(!(Files.exists(p) && !Files.isDirectory(p))) { \"Output path $p exists and is not a directory\" }","typeGuard":null,"tryCatchPattern":"try {\n  runner.writeMultipleFileOutput(outputFiles)\n} catch (e: CliException) {\n  System.err.println(e.message)\n}","preventionTips":["Ensure the multiple-file output path is either nonexistent or a directory.","Remove stale single-file outputs before switching to multi-file output mode.","Use distinct paths for single-file and multiple-file output in scripts."],"tags":["cli","filesystem","output-path"],"backgroundTag":"path-is-not-a-directory","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}