{"record":{"id":"acbe289b9d490f98","repo":"upstash/context7","slug":"failed-to-write-to-skillpath-error-message","errorCode":null,"errorMessage":"Failed to write to ${skillPath}: ${error.message}","messagePattern":"Failed to write to (.+?): (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/cli/src/commands/generate.ts","lineNumber":533,"sourceCode":"\n  for (const targetDir of targetDirs) {\n    let finalDir = targetDir;\n    if (options.output && !targetDir.includes(\"/.config/\") && !targetDir.startsWith(homedir())) {\n      finalDir = targetDir.replace(process.cwd(), options.output);\n    }\n    const skillDir = join(finalDir, skillName);\n    const skillPath = join(skillDir, \"SKILL.md\");\n\n    try {\n      await mkdir(skillDir, { recursive: true });\n      await writeFile(skillPath, generatedContent!, \"utf-8\");\n    } catch (err) {\n      const error = err as NodeJS.ErrnoException;\n      if (error.code === \"EACCES\" || error.code === \"EPERM\") {\n        permissionError = true;\n        failedDirs.add(skillDir);\n      } else {\n        log.warn(`Failed to write to ${skillPath}: ${error.message}`);\n      }\n    }\n  }\n\n  if (permissionError) {\n    writeSpinner.fail(pc.red(\"Permission denied\"));\n    log.blank();\n    console.log(pc.yellow(\"Fix permissions with:\"));\n    for (const dir of failedDirs) {\n      const parentDir = join(dir, \"..\");\n      console.log(pc.dim(`  sudo chown -R $(whoami) \"${parentDir}\"`));\n    }\n    log.blank();\n    return;\n  }\n\n  writeSpinner.succeed(pc.green(`Created skill in ${targetDirs.length} location(s)`));\n  trackEvent(\"gen_install\");","sourceCodeStart":515,"sourceCodeEnd":551,"githubUrl":"https://github.com/upstash/context7/blob/4416fb855b8f752be735e34f943b5d0762701aad/packages/cli/src/commands/generate.ts#L515-L551","documentation":"During skill generation, writing a SKILL.md file to each target skill directory may fail; if the failure isn't a permission error (EACCES/EPERM), the command logs a warning \"Failed to write to <skillPath>: <reason>\" and continues. The write simply didn't happen for that file.","triggerScenarios":"writeFile to skillPath fails with an errno other than EACCES/EPERM: ENOENT (parent dir missing), EISDIR (skillPath is a directory), ENOSPC (disk full), EROFS (read-only filesystem), or EMFILE.","commonSituations":"Disk full on CI runners, skillPath colliding with an existing directory, read-only container filesystems, or a target dir removed between mkdir and write.","solutions":["Read the logged errno/OS message to identify the cause (ENOENT/EISDIR/ENOSPC etc.).","Free disk space if ENOSPC, or remove the conflicting directory if EISDIR.","Ensure the target skills directory exists and is on a writable filesystem.","Re-run context7 generate after fixing; permission problems instead require elevated rights or different --output dir."],"exampleFix":"// before\nawait fs.writeFile(skillPath, content); // EISDIR if skillPath is a dir\n// after\nconst st = await fs.stat(skillPath).catch(() => null);\nif (st?.isDirectory()) await fs.rm(skillPath, { recursive: true });\nawait fs.mkdir(path.dirname(skillPath), { recursive: true });\nawait fs.writeFile(skillPath, content);","handlingStrategy":"validation","validationCode":"await fs.mkdir(path.dirname(skillPath), { recursive: true });\nawait fs.access(path.dirname(skillPath), fs.constants.W_OK);\nconst st = await fs.stat(skillPath).catch(() => null);\nif (st?.isDirectory()) throw new Error(`${skillPath} is a directory`);","typeGuard":null,"tryCatchPattern":"try {\n  await fs.writeFile(skillPath, content);\n} catch (e) {\n  const code = (e as NodeJS.ErrnoException).code;\n  if (code === 'ENOSPC') console.error('Disk full: free space and rerun');\n  else if (code === 'EISDIR') console.error(`${skillPath} is a directory`);\n  else throw e;\n}","preventionTips":["Check free disk space before bulk generation on CI runners","Ensure the output directory exists and is writable before generating","Avoid paths that collide with existing directories","Run in containers with a writable workdir, not a read-only root filesystem"],"tags":["filesystem","cli","file-write"],"backgroundTag":"file-write-failed","analyzedSha":"4416fb855b8f752be735e34f943b5d0762701aad","analyzedAt":"2026-09-16T20:28:07.148Z","contentChangedAt":"2026-09-16T20:28:07.148Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}