{"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":null,"httpStatus":500,"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/20f6d3546c1938bfea1ad304f58a592dddcc5948/server/models/workspaceParsedFiles.js#L104-L140","documentation":"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 }.","triggerScenarios":"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 {}.","commonSituations":"Upgrading across versions that changed the metadata shape; manually seeded workspace_parsed_files rows; storage migrations that rewrote metadata; processes killed mid-upload.","solutions":["Inspect the row's metadata column and confirm the JSON contains a location value","Re-upload the file so a complete record is created","Backfill metadata.location from storage filenames if the bytes still exist","Guard before calling: parse metadata and verify .location is a non-empty string"],"exampleFix":"// before\nawait WorkspaceParsedFiles.moveToDocumentsAndEmbed(user, fileId, workspace);\n\n// after\nconst parsed = await WorkspaceParsedFiles.get({ id: Number(fileId), workspaceId: workspace.id });\nconst location = safeJsonParse(parsed?.metadata, {}).location;\nif (!location) {\n  return res.status(422).json({ error: \"No file location in metadata - re-upload the file\" });\n}\nawait WorkspaceParsedFiles.moveToDocumentsAndEmbed(user, fileId, workspace);","handlingStrategy":"validation","validationCode":"const parsed = await WorkspaceParsedFiles.get({ id: Number(fileId), workspaceId: workspace.id });\nconst location = safeJsonParse(parsed?.metadata, {}).location;\nif (typeof location !== \"string\" || !location) {\n  return res.status(422).json({ error: \"Parsed file has no location metadata - re-upload\" });\n}","typeGuard":null,"tryCatchPattern":"const { success, error } = await WorkspaceParsedFiles.moveToDocumentsAndEmbed(user, fileId, workspace);\nif (!success && /No file location in metadata/i.test(error)) {\n  // ask the user to re-upload; the record cannot be recovered\n}","preventionTips":["Write metadata.location atomically with record creation during upload","Audit rows after version upgrades that change metadata shape","Never insert workspace_parsed_files rows by hand without location"],"tags":["metadata","file","workspace","json"],"backgroundTag":"missing-metadata-field","analyzedSha":"20f6d3546c1938bfea1ad304f58a592dddcc5948","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}