{"record":{"id":"817b5e19d62b50db","repo":"Mintplex-Labs/anything-llm","slug":"no-file-location-in-metadata","errorCode":null,"errorMessage":"No file location in metadata","messagePattern":"No file location in metadata","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/models/workspaceParsedFiles.js","lineNumber":122,"sourceCode":"   * Moves a parsed file to the documents and embeds it.\n   * @param {import(\"@prisma/client\").users | null} user - The user performing the operation.\n   * @param {number} fileId - The ID of the parsed file.\n   * @param {import(\"@prisma/client\").workspaces} workspace - The workspace the file belongs to.\n   * @returns {Promise<{ success: boolean, error: string | null, document: import(\"@prisma/client\").workspace_documents | null }>} The result of the operation.\n   */\n  moveToDocumentsAndEmbed: async function (user = null, fileId, workspace) {\n    try {\n      const parsedFile = await this.get({\n        id: parseInt(fileId),\n        ...(user ? { userId: user.id } : {}),\n        workspaceId: workspace.id,\n      });\n      if (!parsedFile) throw new Error(\"File not found\");\n\n      // Get file location from metadata\n      const metadata = safeJsonParse(parsedFile.metadata, {});\n      const location = metadata.location;\n      if (!location) throw new Error(\"No file location in metadata\");\n\n      // Get file from metadata location\n      const sourceFile = path.join(directUploadsPath, path.basename(location));\n      if (!fs.existsSync(sourceFile)) throw new Error(\"Source file not found\");\n\n      // Move to custom-documents\n      const customDocsPath = path.join(documentsPath, \"custom-documents\");\n      if (!fs.existsSync(customDocsPath))\n        fs.mkdirSync(customDocsPath, { recursive: true });\n\n      // Copy the file to custom-documents\n      const targetPath = path.join(customDocsPath, path.basename(location));\n      fs.copyFileSync(sourceFile, targetPath);\n      fs.unlinkSync(sourceFile);\n\n      const {\n        failedToEmbed = [],\n        errors = [],","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/models/workspaceParsedFiles.js#L104-L140","documentation":"Thrown by WorkspaceParsedFiles.moveToDocumentsAndEmbed when the parsed file's metadata (JSON) either fails to parse or contains no 'location' field. safeJsonParse defaults to {}, and a missing location key is treated as a failure because the embedding step needs the original file path.","triggerScenarios":"Calling embed on a workspace_parsed_files row whose metadata column is null, malformed JSON, or a valid JSON object lacking a 'location' property.","commonSituations":"The upload/parse pipeline that created the row crashed or was interrupted before writing metadata.location. A schema/version change dropped the location field. Manual DB edits corrupted the metadata JSON.","solutions":["Re-run the original file upload/parse so the row is recreated with complete metadata including location.","Delete the orphaned parsed-file row and re-upload the source file.","If repairing by hand, backfill metadata.location to point at the file under the direct uploads path."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const meta = safeJsonParse(parsedFile.metadata, {});\nif (!meta || !meta.location) {\n  return respond(409, 'Parsed file missing location metadata; re-upload the source');\n}","typeGuard":"const hasLocation = (m) => m != null && typeof m === 'object' && typeof m.location === 'string' && m.location.length > 0;","tryCatchPattern":"const { success, error } = await WorkspaceParsedFiles.moveToDocumentsAndEmbed(user, fileId, workspace);\nif (!success && /No file location/.test(error)) {\n  // delete the orphaned row and prompt re-upload\n}","preventionTips":["Ensure the upload/parse pipeline always writes metadata.location atomically with the row.","Treat parsed-file rows without location as corrupt and re-create them."],"tags":["workspace","parsed-files","metadata","data-integrity"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}