{"record":{"id":"8f40d09d8299c0b1","repo":"yamadashy/repomix","slug":"failed-to-copy-output-file-error-as-error-mes","errorCode":null,"errorMessage":"Failed to copy output file: ${(error as Error).message}","messagePattern":"Failed to copy output file: (.+?)","errorType":"exception","errorClass":"RepomixError","httpStatus":null,"severity":"error","filePath":"src/cli/actions/remoteAction.ts","lineNumber":322,"sourceCode":"\n    await fs.copyFile(sourcePath, targetPath);\n  } catch (error) {\n    const nodeError = error as NodeJS.ErrnoException;\n\n    // Provide helpful message for permission errors\n    if (nodeError.code === 'EPERM' || nodeError.code === 'EACCES') {\n      throw new RepomixError(\n        `Failed to copy output file to ${targetPath}: Permission denied.\n\nThe current directory may be protected or require elevated permissions.\nPlease try one of the following:\n  • Run from a different directory (e.g., your home directory or Documents folder)\n  • Use the --output flag to specify a writable location: --output ~/repomix-output.xml\n  • Use --stdout to print output directly to the console`,\n      );\n    }\n\n    throw new RepomixError(`Failed to copy output file: ${(error as Error).message}`);\n  }\n};\n","sourceCodeStart":304,"sourceCodeEnd":325,"githubUrl":"https://github.com/yamadashy/repomix/blob/f465ad909315a22120636baf03fa5e28701a50cb/src/cli/actions/remoteAction.ts#L304-L325","documentation":"Fallback error in `copyOutputToCurrentDirectory`: any copy failure that is not EPERM/EACCES (e.g. ENOSPC disk full, EISDIR, ENOENT) is wrapped into a RepomixError carrying the underlying Node error message. It signals the packed output file could not be moved to the requested target path.","triggerScenarios":"`fs.copyFile(sourcePath, targetPath)` in `copyOutputToCurrentDirectory` (via `runRemoteAction`) rejects with any errno code other than EPERM/EACCES — e.g. target is a directory (EISDIR), disk full (ENOSPC), source vanished (ENOENT).","commonSituations":"Passing `--output` pointing to an existing directory name, a full disk during a large pack, or antivirus/backup tooling locking the destination file on Windows.","solutions":["Read the inner message to identify the errno code and address it","If `--output` points to a directory, change it to a file path","Free disk space if the message indicates ENOSPC","Retry if a transient file lock (AV/indexer) was holding the target"],"exampleFix":"// before\nrepomix --remote user/repo --output ./out-dir\n// after\nrepomix --remote user/repo --output ./out-dir/repomix-output.xml","handlingStrategy":"try-catch","validationCode":"const target = path.resolve(outPath);\nif (await stat(target).then(s => s.isDirectory(), () => false)) {\n  throw new Error('--output must be a file path, not a directory');\n}","typeGuard":"const isErrno = (e: unknown): e is NodeJS.ErrnoException =>\n  e instanceof Error && typeof (e as any).code === 'string';","tryCatchPattern":"try {\n  await runRepomix({ remote: url, output: outPath });\n} catch (e) {\n  if (e instanceof RepomixError && e.message.startsWith('Failed to copy output file:')) {\n    console.error(e.message); // includes underlying errno (ENOSPC, EISDIR, ...)\n  }\n  throw e;\n}","preventionTips":["Ensure `--output` is a file path, not an existing directory","Keep sufficient free disk space before packing large repos","Exclude the output path from AV/backup lockers or retry on transient locks"],"tags":["filesystem","copy-file","enospc"],"backgroundTag":"file-copy-failed","analyzedSha":"f465ad909315a22120636baf03fa5e28701a50cb","analyzedAt":"2026-08-29T01:27:42.024Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}