Mintplex-Labs/anything-llm · error

No file location in metadata

Error message

No file location in metadata

What it means

Thrown when the parsed-file row exists but its metadata JSON has no location key. The code runs safeJsonParse(parsedFile.metadata, {}), so unparseable or partial metadata also collapses to {} and fails here. metadata.location is the pointer to the uploaded bytes; without it the method cannot locate the file on disk. Caught internally and returned as { success: false, error, document: null }.

Solutions

  1. Inspect the row's metadata column and confirm the JSON contains a location value
  2. Re-upload the file so a complete record is created
  3. Backfill metadata.location from storage filenames if the bytes still exist
  4. Guard before calling: parse metadata and verify .location is a non-empty string

Example fix

// before
await WorkspaceParsedFiles.moveToDocumentsAndEmbed(user, fileId, workspace);

// after
const parsed = await WorkspaceParsedFiles.get({ id: Number(fileId), workspaceId: workspace.id });
const location = safeJsonParse(parsed?.metadata, {}).location;
if (!location) {
  return res.status(422).json({ error: "No file location in metadata - re-upload the file" });
}
await WorkspaceParsedFiles.moveToDocumentsAndEmbed(user, fileId, workspace);
Defensive patterns

Strategy: validation

Validate before calling

const parsed = await WorkspaceParsedFiles.get({ id: Number(fileId), workspaceId: workspace.id });
const location = safeJsonParse(parsed?.metadata, {}).location;
if (typeof location !== "string" || !location) {
  return res.status(422).json({ error: "Parsed file has no location metadata - re-upload" });
}

Try / catch

const { success, error } = await WorkspaceParsedFiles.moveToDocumentsAndEmbed(user, fileId, workspace);
if (!success && /No file location in metadata/i.test(error)) {
  // ask the user to re-upload; the record cannot be recovered
}

Prevention

When it happens

Trigger: Rows written by an interrupted upload that never stored metadata; a crash between record creation and metadata save; direct DB inserts without a location field; metadata JSON corrupted (truncated, wrong encoding) so parsing falls back to {}.

Common situations: Upgrading across versions that changed the metadata shape; manually seeded workspace_parsed_files rows; storage migrations that rewrote metadata; processes killed mid-upload.

Related errors


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

Appendix: source

Thrown at server/models/workspaceParsedFiles.js:122

   * Moves a parsed file to the documents and embeds it.
   * @param {import("@prisma/client").users | null} user - The user performing the operation.
   * @param {number} fileId - The ID of the parsed file.
   * @param {import("@prisma/client").workspaces} workspace - The workspace the file belongs to.
   * @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 = [],

View on GitHub (pinned to 20f6d3546c)