upstash/context7 · warning
Failed to write to
Error message
Failed to write to ${skillPath}: ${error.message} What it means
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.
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.
Example fix
// before
await fs.writeFile(skillPath, content); // EISDIR if skillPath is a dir
// after
const st = await fs.stat(skillPath).catch(() => null);
if (st?.isDirectory()) await fs.rm(skillPath, { recursive: true });
await fs.mkdir(path.dirname(skillPath), { recursive: true });
await fs.writeFile(skillPath, content); Defensive patterns
Strategy: validation
Validate before calling
await fs.mkdir(path.dirname(skillPath), { recursive: true });
await fs.access(path.dirname(skillPath), fs.constants.W_OK);
const st = await fs.stat(skillPath).catch(() => null);
if (st?.isDirectory()) throw new Error(`${skillPath} is a directory`); Try / catch
try {
await fs.writeFile(skillPath, content);
} catch (e) {
const code = (e as NodeJS.ErrnoException).code;
if (code === 'ENOSPC') console.error('Disk full: free space and rerun');
else if (code === 'EISDIR') console.error(`${skillPath} is a directory`);
else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Disk full on CI runners, skillPath colliding with an existing directory, read-only container filesystems, or a target dir removed between mkdir and write.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- Failed to install
- Fix permissions with:
- await describeErrorResponse(response, fallback)
- Cancelled
- Context7 base URL must not contain a query string or…
AI-assisted analysis of upstash/context7@4416fb855b (2026-09-16).
Data as JSON: /api/errors/acbe289b9d490f98.
Report an issue: GitHub.
Appendix: source
Thrown at packages/cli/src/commands/generate.ts:533
for (const targetDir of targetDirs) {
let finalDir = targetDir;
if (options.output && !targetDir.includes("/.config/") && !targetDir.startsWith(homedir())) {
finalDir = targetDir.replace(process.cwd(), options.output);
}
const skillDir = join(finalDir, skillName);
const skillPath = join(skillDir, "SKILL.md");
try {
await mkdir(skillDir, { recursive: true });
await writeFile(skillPath, generatedContent!, "utf-8");
} catch (err) {
const error = err as NodeJS.ErrnoException;
if (error.code === "EACCES" || error.code === "EPERM") {
permissionError = true;
failedDirs.add(skillDir);
} else {
log.warn(`Failed to write to ${skillPath}: ${error.message}`);
}
}
}
if (permissionError) {
writeSpinner.fail(pc.red("Permission denied"));
log.blank();
console.log(pc.yellow("Fix permissions with:"));
for (const dir of failedDirs) {
const parentDir = join(dir, "..");
console.log(pc.dim(` sudo chown -R $(whoami) "${parentDir}"`));
}
log.blank();
return;
}
writeSpinner.succeed(pc.green(`Created skill in ${targetDirs.length} location(s)`));
trackEvent("gen_install");View on GitHub (pinned to 4416fb855b)