{"record":{"id":"c8a7bca34a23923e","repo":"Mintplex-Labs/anything-llm","slug":"file-not-found","errorCode":null,"errorMessage":"File not found","messagePattern":"File not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/models/workspaceParsedFiles.js","lineNumber":117,"sourceCode":"    });\n    return _sum.tokenCountEstimate || 0;\n  },\n\n  /**\n   * 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);","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/models/workspaceParsedFiles.js#L99-L135","documentation":"Thrown by WorkspaceParsedFiles.moveToDocumentsAndEmbed when this.get({id, userId?, workspaceId}) returns null — i.e. no workspace_parsed_files row matches the given fileId (optionally scoped to the acting user) and the workspace. Reached via POST /workspace/:slug/embed-parsed-file/:fileId.","triggerScenarios":"POST /workspace/:slug/embed-parsed-file/:fileId where the fileId does not exist, belongs to a different workspace, or (when a user is passed) belongs to a different user. Also if the file was already processed (the finally block deletes the row on every run).","commonSituations":"The parsed file was already embedded and its row deleted by a previous attempt. User retries after the first success. Cross-workspace fileId copy/paste. Stale UI listing a fileId that no longer exists.","solutions":["Confirm the fileId still exists in workspace_parsed_files for this workspace before calling.","Avoid retrying after a success — the row is removed in finally.","If acting as a non-admin, ensure the file belongs to that user (userId scope)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const parsedFile = await WorkspaceParsedFiles.get({ id: fileId, workspaceId: workspace.id });\nif (!parsedFile) return respond(404, 'Parsed file not found');","typeGuard":null,"tryCatchPattern":"const { success, error } = await WorkspaceParsedFiles.moveToDocumentsAndEmbed(user, fileId, workspace);\nif (!success && /File not found/.test(error)) {\n  // tell the client to refresh its parsed-file list\n}","preventionTips":["Do not retry embed after a success — the parsed-file row is deleted in finally.","Scope fileId lookups by workspace (and user) to avoid cross-tenant mismatches."],"tags":["workspace","parsed-files","embedding","not-found"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}