Mintplex-Labs/anything-llm · error · Error

Parent directory does not exist: ${parentDir}

Error message

Parent directory does not exist: ${parentDir}

What it means

Thrown by validatePath() when the requested file does not exist (ENOENT from realpath) AND realpath of the parent directory also throws - meaning the parent directory itself does not exist. The file cannot be created because its containing directory is missing. The parentDir is interpolated into the message.

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 526360e320)

Solutions

  1. Create the parent directory (recursively) before referencing the file path.
  2. Verify the directory portion of the path exists with getFileStats or listDirectory.
  3. Correct typos in the directory segments of the path.

Example fix

// before - writing to a path whose parent does not exist
await filesystem.writeFileContent("workspace/new/sub/file.txt", "data");
// after - create the parent directory first
await fs.mkdir(path.join(allowedDir, "new", "sub"), { recursive: true });
await filesystem.writeFileContent("workspace/new/sub/file.txt", "data");
Defensive patterns

Strategy: validation

Validate before calling

const fs = require("fs/promises");
async function ensureParentExists(p) {
  const parent = path.dirname(p);
  try { await fs.access(parent); }
  catch { await fs.mkdir(parent, { recursive: true }); }
}

Try / catch

try { await filesystem.validatePath(p); }
catch (e) {
  if (e.message.startsWith("Parent directory does not exist")) {
    await fs.mkdir(path.dirname(resolved), { recursive: true });
    // retry
  } else throw e;
}

Prevention

When it happens

Trigger: Validating a path to a file in a directory that does not exist, e.g., workspace/new/sub/file.txt where workspace/new/sub has not been created. realpath fails on both the file and the parent, so the catch block throws this.

Common situations: An agent writing to a deeply nested path without first creating intermediate directories; a typo in a directory segment; assuming a directory exists when it does not.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13). Data as JSON: /api/errors/f0886794183fb6b1. Report an issue: GitHub.