Mintplex-Labs/anything-llm · error · Error
Parent directory does not exist
Error message
Parent directory does not exist: ${parentDir} What it means
Thrown by validatePath when the target file does not exist and fs.realpath of its parent directory also fails — meaning the parent directory itself is missing. Any catch inside that inner try (not just ENOENT, e.g. ENOTDIR when a path component is a file, or permission errors) collapses into this single message. It typically surfaces from write/create calls that target a directory chain that was never created.
Solutions
- Create the directory chain first with the create_directory tool (or fs.mkdir with recursive: true), then retry the write.
- Verify the exact chain with list_directory and correct typos in path components.
- Check that no intermediate component is a file rather than a directory (ENOTDIR masquerades as this error).
Example fix
// before
write_file({ path: "docs/2026/report.md", content })
// -> Error: Parent directory does not exist: .../docs/2026
// after
create_directory({ path: "docs/2026" });
write_file({ path: "docs/2026/report.md", content }); Defensive patterns
Strategy: validation
Validate before calling
const fs = require("fs").promises;
const path = require("path");
async function ensureParentDir(target) {
const parent = path.dirname(path.resolve(target));
const st = await fs.stat(parent).catch(() => null);
if (!st?.isDirectory()) await fs.mkdir(parent, { recursive: true });
}
await ensureParentDir(target); // now safe to write Try / catch
try {
await fileOps.writeFileContent(p, content);
} catch (e) {
if (e.message.startsWith("Parent directory does not exist")) {
await fs.mkdir(path.dirname(p), { recursive: true });
await fileOps.writeFileContent(p, content); // one retry after creating the chain
} else throw e;
} Prevention
- Instruct agents to create_directory before write_file into new nested paths.
- Wrap file-creation flows with an ensureParentDir helper using mkdir recursive.
- Watch for typos in path components — they create phantom directories or hit this error.
When it happens
Trigger: write_file({ path: "docs/2026/report.md" }) when docs/2026/ does not exist anywhere under the allowed root; a path component is actually a regular file (docs is a file, so realpath of docs/ fails with ENOTDIR); intermediate directory deleted between a list_directory call and the write.
Common situations: Agent assumes nested folders exist and writes directly; user expects mkdir -p semantics from write_file; path typo creates a nonexistent chain like storage-dir/Documnets/file.txt.
Related errors
- Access denied - parent directory outside allowed…
- Access denied - path outside allowed directories.
- Could not find exact match for edit:\n
- Access denied - symlink target outside allowed directories.
- Cannot copy symbolic link
AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18).
Data as JSON: /api/errors/f0886794183fb6b1.
Report an issue: GitHub.
Appendix: source
Thrown at server/utils/agents/aibitat/plugins/filesystem/lib.js:470
try {
const realParentPath = await fs.realpath(parentDir);
const normalizedParent = this.#normalizePath(realParentPath);
if (
!this.#isPathWithinAllowedDirectories(
normalizedParent,
this.#allowedDirectories
)
) {
console.log(
`[validatePath] Access denied - parent directory outside allowed directories: ${realParentPath} not in ${this.#allowedDirectories.join(", ")}`
);
throw new Error(
`Access denied - parent directory outside allowed directories.`
);
}
return absolute;
} catch {
throw new Error(`Parent directory does not exist: ${parentDir}`);
}
}
throw error;
}
}
/**
* Gets detailed file statistics.
* @param {string} filePath - Path to the file
* @returns {Promise<Object>} File statistics
*/
async getFileStats(filePath) {
const stats = await fs.stat(filePath);
return {
size: stats.size,
sizeFormatted: humanFileSize(stats.size, true, 2),
created: stats.birthtime.toISOString(),
modified: stats.mtime.toISOString(),View on GitHub (pinned to 3aec848f28)