{"record":{"id":"b2bf44be413a6d6f","repo":"yamadashy/repomix","slug":"failed-to-write-skill-output-error-instanceof-e","errorCode":null,"errorMessage":"Failed to write skill output: ${error instanceof Error ? error.message : String(error)}","messagePattern":"Failed to write skill output: (.+?)","errorType":"exception","errorClass":"RepomixError","httpStatus":null,"severity":"error","filePath":"src/core/skill/writeSkillOutput.ts","lineNumber":54,"sourceCode":"    await deps.writeFile(path.join(referencesDir, 'summary.md'), output.references.summary, 'utf-8');\n    await deps.writeFile(path.join(referencesDir, 'project-structure.md'), output.references.structure, 'utf-8');\n    await deps.writeFile(path.join(referencesDir, 'files.md'), output.references.files, 'utf-8');\n\n    // Write tech-stacks.md if available\n    if (output.references.techStack) {\n      await deps.writeFile(path.join(referencesDir, 'tech-stacks.md'), output.references.techStack, 'utf-8');\n    }\n\n    return skillDir;\n  } catch (error) {\n    const nodeError = error as NodeJS.ErrnoException;\n    if (nodeError.code === 'EPERM' || nodeError.code === 'EACCES') {\n      throw new RepomixError(\n        `Failed to write skill output to ${skillDir}: Permission denied. Please check directory permissions.`,\n        { cause: error instanceof Error ? error : undefined },\n      );\n    }\n    throw new RepomixError(`Failed to write skill output: ${error instanceof Error ? error.message : String(error)}`, {\n      cause: error instanceof Error ? error : undefined,\n    });\n  }\n};\n","sourceCodeStart":36,"sourceCodeEnd":59,"githubUrl":"https://github.com/yamadashy/repomix/blob/f465ad909315a22120636baf03fa5e28701a50cb/src/core/skill/writeSkillOutput.ts#L36-L59","documentation":"This is the catch-all wrapper in writeSkillOutput: any filesystem failure that is NOT EPERM/EACCES is rethrown as a RepomixError with 'Failed to write skill output: <message>'. It preserves the original error as cause so callers can inspect the root cause.","triggerScenarios":"Any fs error other than EPERM/EACCES while creating or writing skillDir — ENOSPC (disk full), ENOENT (parent path vanished), EISDIR, EMFILE/ENFILE (fd exhaustion), EROFS, or a non-Error throw.","commonSituations":"Disk quota exceeded on CI; antivirus/file-lock interference on Windows; target path exists as a file not a directory; too many open files.","solutions":["Read error.cause (or the appended message) to identify the underlying errno code","Free disk space if the cause is ENOSPC","Remove any file occupying the skillDir path so the directory can be created","Close fd leaks / raise ulimit if the cause is EMFILE","Retry the command after fixing the environment"],"exampleFix":"// before (skillDir occupied by a regular file)\n$ ls ~/.claude/skills/repomix   # -> a file\n// after\n$ rm ~/.claude/skills/repomix && repomix --skill","handlingStrategy":"try-catch","validationCode":"import { stat } from 'node:fs/promises';\nconst s = await stat(path.dirname(skillDir)).catch(() => null);\nif (!s?.isDirectory()) throw new Error(`parent of skillDir missing: ${skillDir}`);\nif (await stat(skillDir).then(s2 => !s2.isDirectory(), () => false)) throw new Error('skillDir exists as a file');","typeGuard":"const hasCause = (e: unknown): e is { cause: unknown } =>\n  typeof e === 'object' && e !== null && 'cause' in e;","tryCatchPattern":"try {\n  await writeSkillOutput(skillDir, output);\n} catch (err) {\n  const cause = (err as { cause?: Error })?.cause;\n  console.error(`skill write failed: ${cause?.message ?? err.message}`); // route on ENOSPC/ENOENT etc.\n}","preventionTips":["Monitor free disk space before large outputs","Ensure the skillDir path is not occupied by a regular file","Check df/quota on CI runners","Inspect error.cause to distinguish ENOSPC vs ENOENT vs transient locks"],"tags":["filesystem","io","skill-output"],"backgroundTag":"fs-write-failure","analyzedSha":"f465ad909315a22120636baf03fa5e28701a50cb","analyzedAt":"2026-08-29T01:27:42.024Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}