{"record":{"id":"a9c1ad5d516d057b","repo":"paperclipai/paperclip","slug":"output-directory-already-exists-and-is-not-empty","errorCode":null,"errorMessage":"Output directory already exists and is not empty: ${outputDir}","messagePattern":"Output directory already exists and is not empty: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli/src/commands/client/feedback.ts","lineNumber":563,"sourceCode":"\nfunction padRight(value: string, width: number): string {\n  return `${value}${\" \".repeat(Math.max(0, width - value.length))}`;\n}\n\nfunction defaultFeedbackExportDirName(): string {\n  const iso = new Date().toISOString().replace(/[-:]/g, \"\").replace(/\\.\\d{3}Z$/, \"Z\");\n  return `feedback-export-${iso}`;\n}\n\nasync function ensureEmptyOutputDirectory(outputDir: string): Promise<void> {\n  try {\n    const info = await stat(outputDir);\n    if (!info.isDirectory()) {\n      throw new Error(`Output path already exists and is not a directory: ${outputDir}`);\n    }\n    const entries = await readdir(outputDir);\n    if (entries.length > 0) {\n      throw new Error(`Output directory already exists and is not empty: ${outputDir}`);\n    }\n  } catch (error) {\n    const message = error instanceof Error ? error.message : \"\";\n    if (/ENOENT/.test(message)) {\n      await mkdir(outputDir, { recursive: true });\n      return;\n    }\n    throw error;\n  }\n}\n\nasync function collectJsonFilesForArchive(\n  outputDir: string,\n  relativePaths: string[],\n): Promise<Record<string, string>> {\n  const files: Record<string, string> = {};\n  for (const relativePath of relativePaths) {\n    const normalized = relativePath.replace(/\\\\/g, \"/\");","sourceCodeStart":545,"sourceCodeEnd":581,"githubUrl":"https://github.com/paperclipai/paperclip/blob/67001ec6eb96ae601aa27bc91d9b2415d665334a/cli/src/commands/client/feedback.ts#L545-L581","documentation":"ensureEmptyOutputDirectory throws when the target path is an existing directory that already contains entries, to prevent silently merging new export files with old content.","triggerScenarios":"Passing --output <dir> where <dir> exists and is non-empty.","commonSituations":"Re-running an export into the same directory; pointing --output at a project folder.","solutions":["Empty or remove the existing directory first.","Choose a new --output path.","Omit --output to get a fresh timestamped default directory."],"exampleFix":"// before\npaperclipai feedback trace export --output ./traces\n// after\nrm -rf ./traces && paperclipai feedback trace export --output ./traces","handlingStrategy":"validation","validationCode":"import {readdir} from 'node:fs/promises';\nconst entries = await readdir(outputDir);\nif (entries.length > 0) throw new Error(`Output directory already exists and is not empty: ${outputDir}`);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use a fresh --output per run or omit it for a timestamped default.","Clean export directories in CI between runs."],"tags":["cli","feedback","filesystem","io"],"backgroundTag":null,"analyzedSha":"67001ec6eb96ae601aa27bc91d9b2415d665334a","analyzedAt":"2026-08-12T12:05:45.408Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}