{"record":{"id":"13ef20a753011b1d","repo":"Egonex-AI/Understand-Anything","slug":"a-benchmark-report-target-is-a-directory","errorCode":null,"errorMessage":"A benchmark report target is a directory","messagePattern":"A benchmark report target is a directory","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/lib/large-repo-benchmark.mjs","lineNumber":802,"sourceCode":"}\n\nfunction fileSizeOrZero(path) {\n  try {\n    return statSync(path).size;\n  } catch {\n    return 0;\n  }\n}\n\nfunction writeJson(path, value) {\n  mkdirSync(dirname(path), { recursive: true });\n  writeFileSync(path, `${JSON.stringify(value, null, 2)}\\n`, 'utf-8');\n}\n\nfunction preflightReportTargets(paths, fileSystem) {\n  for (const path of paths) {\n    if (fileSystem.existsSync(path) && fileSystem.statSync(path).isDirectory()) {\n      throw new Error('A benchmark report target is a directory');\n    }\n  }\n}\n\nfunction tryRemove(path, fileSystem) {\n  try {\n    fileSystem.rmSync(path, { force: true });\n    return true;\n  } catch {\n    return false;\n  }\n}\n\nfunction rollbackReportEntry(entry, fileSystem, recovery) {\n  if (entry.backupMoved) {\n    if (!tryRemove(entry.targetPath, fileSystem)) {\n      recovery.rollbackRemoveFailures += 1;\n    }","sourceCodeStart":784,"sourceCodeEnd":820,"githubUrl":"https://github.com/Egonex-AI/Understand-Anything/blob/32944829e7a63a9fa9c55d811d7f98a9530c6a6a/scripts/lib/large-repo-benchmark.mjs#L784-L820","documentation":"Thrown by preflightReportTargets during the atomic report-delivery transaction. Before acquiring the pair lock or writing temp files, the harness checks each target path (the JSON output path and the markdown path); if any already exists and resolves to a directory, delivery aborts. This prevents the subsequent writeFileSync/renameSync from failing mid-transaction with EISDIR, which would leave backups stranded.","triggerScenarios":"deliverBenchmarkReports is called with outputPath and/or markdownPath that point at an existing directory (e.g. the user passed --output ./reports where ./reports is a folder). preflightReportTargets calls fs.existsSync then fs.statSync().isDirectory() on each and throws on the first directory hit.","commonSituations":"Passing a directory path as --output or --markdown (common when a user expects the tool to derive a filename inside it). A previous run created a file at that path which was later replaced by a directory. CI that mounts a directory volume at the output location. Shell completion appending a trailing slash that resolves to an existing dir.","solutions":["Pass explicit file paths (with .json and .md extensions) rather than a directory: --output ./reports/bench.json --markdown ./reports/bench.md.","If you intended a directory, pre-create the file names inside it and reference those files directly.","Remove or rename the directory currently occupying the target path: rm -rf <path> (only after confirming it is not needed).","Check both --output and --markdown; the error fires on whichever resolves to a directory first."],"exampleFix":"// before\nnode scripts/large-repo-benchmark.mjs --output ./reports --markdown ./reports\n\n// after — point at files, not the directory\nnode scripts/large-repo-benchmark.mjs --output ./reports/bench.json --markdown ./reports/bench.md","handlingStrategy":"validation","validationCode":"import { existsSync, statSync } from 'node:fs';\nfunction ensureReportTargetsAreFiles(paths) {\n  for (const p of paths) {\n    if (existsSync(p) && statSync(p).isDirectory()) {\n      throw new Error(`Refusing to overwrite directory at ${p}; pass a file path.`);\n    }\n  }\n}\n// before calling deliverBenchmarkReports:\nensureReportTargetsAreFiles([options.outputPath, options.markdownPath]);","typeGuard":null,"tryCatchPattern":"try {\n  deliverBenchmarkReports(opts);\n} catch (e) {\n  if (e instanceof BenchmarkReportWriteError) {\n    // preflight failures are not in recovery; surface the cause clearly\n    console.error('report delivery preflight failed:', e.message);\n  }\n  throw e;\n}","preventionTips":["Always pass file paths (with extensions), never a bare directory, to --output / --markdown.","Validate paths with statSync().isFile() before invoking the benchmark.","In CI, assert the output path does not exist or is a regular file before the run."],"tags":["benchmark","filesystem","report-delivery","preflight","configuration"],"backgroundTag":null,"analyzedSha":"32944829e7a63a9fa9c55d811d7f98a9530c6a6a","analyzedAt":"2026-08-12T10:25:44.261Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}