Mintplex-Labs/anything-llm · error

Source file not found

Error message

Source file not found

What it means

Thrown when the file named by metadata.location no longer exists under the direct-uploads storage directory: the code joins directUploadsPath with path.basename(location) and checks fs.existsSync before copying. The bytes were expected at upload time but vanished before the move-to-documents step. Caught internally and returned as { success: false, error, document: null }.

Solutions

  1. Make the storage directory persistent and identical across restarts (mount the volume, keep STORAGE_DIR stable)
  2. Pre-check fs.existsSync(path.join(directUploadsPath, path.basename(location))) before calling
  3. Re-upload the file if the bytes are gone
  4. On multi-node setups, put direct uploads on shared storage reachable by every worker

Example fix

# before - storage lost on every recreate
docker run -p 3001:3001 mintplexlabs/anythingllm

# after - persist the storage directory
docker run -p 3001:3001 -v anythingllm_storage:/app/storage mintplexlabs/anythingllm
Defensive patterns

Strategy: validation

Validate before calling

const location = safeJsonParse(parsed.metadata, {}).location;
const sourceFile = path.join(directUploadsPath, path.basename(location));
if (!fs.existsSync(sourceFile)) {
  return res.status(410).json({ error: "Source file missing from storage - re-upload" });
}

Try / catch

const { success, error } = await WorkspaceParsedFiles.moveToDocumentsAndEmbed(user, fileId, workspace);
if (!success && /Source file not found/i.test(error)) {
  // storage drifted: verify STORAGE_DIR / volume mounts before retrying with a new upload
}

Prevention

When it happens

Trigger: STORAGE_DIR changed or the storage folder moved between upload and embed; the container/pod was recreated without the storage volume; a cleanup job (tmp cleaner, cron) deleted the upload; multi-node deployments where the worker lacks the shared volume.

Common situations: Ephemeral container filesystems (no mounted volume for /app/storage or STORAGE_DIR); Kubernetes pods without PVCs; sysadmin tmpwatch hitting the uploads directory; storage migrated to a new path while old rows still point to the previous layout.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@20f6d3546c (2026-08-18). Data as JSON: /api/errors/9a78724fff2dd0c8. Report an issue: GitHub.

Appendix: source

Thrown at server/models/workspaceParsedFiles.js:126

   * @returns {Promise<{ success: boolean, error: string | null, document: import("@prisma/client").workspace_documents | null }>} The result of the operation.
   */
  moveToDocumentsAndEmbed: async function (user = null, fileId, workspace) {
    try {
      const parsedFile = await this.get({
        id: parseInt(fileId),
        ...(user ? { userId: user.id } : {}),
        workspaceId: workspace.id,
      });
      if (!parsedFile) throw new Error("File not found");

      // Get file location from metadata
      const metadata = safeJsonParse(parsedFile.metadata, {});
      const location = metadata.location;
      if (!location) throw new Error("No file location in metadata");

      // Get file from metadata location
      const sourceFile = path.join(directUploadsPath, path.basename(location));
      if (!fs.existsSync(sourceFile)) throw new Error("Source file not found");

      // Move to custom-documents
      const customDocsPath = path.join(documentsPath, "custom-documents");
      if (!fs.existsSync(customDocsPath))
        fs.mkdirSync(customDocsPath, { recursive: true });

      // Copy the file to custom-documents
      const targetPath = path.join(customDocsPath, path.basename(location));
      fs.copyFileSync(sourceFile, targetPath);
      fs.unlinkSync(sourceFile);

      const {
        failedToEmbed = [],
        errors = [],
        embedded = [],
      } = await Document.addDocuments(
        workspace,
        [`custom-documents/${path.basename(location)}`],

View on GitHub (pinned to 20f6d3546c)