{"record":{"id":"b475fafe865cb039","repo":"Mintplex-Labs/anything-llm","slug":"internal-server-error-b475fa","errorCode":null,"errorMessage":"Internal Server Error","messagePattern":"Internal Server Error","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"server/endpoints/memory.js","lineNumber":37,"sourceCode":" * Loads the memory by :memoryId and, in multi-user mode, scopes the query to the requester's userId.\n * A memory owned by another user returns null here and is indistinguishable from \"not found\" — 404 either way.\n */\nasync function validateMemoryOwner(request, response, next) {\n  try {\n    const clause = { id: Number(request.params.memoryId) };\n    if (response.locals.multiUserMode) {\n      const user = await userFromSession(request, response);\n      clause.userId = user?.id ?? null;\n    }\n\n    const memory = await Memory.get(clause);\n    if (!memory)\n      return response.status(404).json({ error: \"Memory not found.\" });\n\n    next();\n  } catch (e) {\n    console.error(e);\n    return response.sendStatus(500);\n  }\n}\n\nfunction memoryEndpoints(app) {\n  if (!app) return;\n\n  app.get(\n    \"/workspaces/:slug/memories\",\n    [\n      validatedRequest,\n      flexUserRoleValid([ROLES.all]),\n      memoryFeatureEnabled,\n      validWorkspaceSlug,\n    ],\n    async (request, response) => {\n      try {\n        const user = await userFromSession(request, response);\n        const workspace = response.locals.workspace;","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/endpoints/memory.js#L19-L55","documentation":"Generic catch-all in the validateMemoryOwner middleware. It loads a memory by :memoryId scoped to the user's ID in multi-user mode. Memory.get has an internal try-catch returning null (which yields a 404), so this 500 fires only from userFromSession throwing unexpectedly or a Prisma client-level failure.","triggerScenarios":"Hitting any /memories/:memoryId route when userFromSession encounters a corrupt JWT that bypasses decodeJWT's catch, or when the Prisma client is in a broken state such that Memory.get's internal catch itself fails.","commonSituations":"JWT_SECRET environment variable changed mid-session causing unexpected JWT behavior, Prisma client not generated or connected, or a schema mismatch after a migration that was not applied to the database.","solutions":["Check server logs for the underlying error from console.error(e).","Verify JWT_SECRET is set and has not changed since the user's session token was issued.","Run npx prisma migrate deploy and npx prisma generate to ensure schema and client are in sync.","Confirm the memories table exists in the database."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Validate memoryId is numeric before DB lookup\nconst memoryId = Number(request.params.memoryId);\nif (!Number.isInteger(memoryId) || memoryId <= 0) {\n  return response.status(400).json({ error: \"Invalid memory ID.\" });\n}","typeGuard":null,"tryCatchPattern":"// The middleware already has a catch; enhance error classification\ncatch (e) {\n  console.error(\"validateMemoryOwner:\", e);\n  if (e?.code === \"P2025\" || e?.message?.includes(\"Prisma\")) {\n    return response.status(503).json({ error: \"Database temporarily unavailable.\" });\n  }\n  return response.sendStatus(500);\n}","preventionTips":["Ensure JWT_SECRET is stable across server restarts.","Run npx prisma generate after every schema change.","Monitor database connection pool metrics."],"tags":["express","middleware","memory","prisma","session"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}