Mintplex-Labs/anything-llm · error

Internal Server Error

Error message

Internal Server Error

What it means

Catch-all 500 for the public embed endpoint GET /embed/:embedId/:sessionId (chat-widget history). EmbedChats.forEmbedByUser already swallows DB errors and returns [], so the 500 almost always comes from the subsequent conversion of rows into chat history (convertToChatHistory) or a hard DB read fault — e.g. a stored chat row with a corrupt JSON payload, or the sqlite file being locked/unreadable. The embed passed middleware, so the embedId itself is valid.

Solutions

  1. Check server console — console.error(e.message, e) names the failing row or DB error
  2. If a specific session's data is corrupt, delete that session's chats (DELETE /embed/:embedId/:sessionId) and start a fresh session
  3. Confirm the storage directory is writable and not shared by two running server instances
  4. Restore storage/anythingllm.db from backup if corruption is systemic
Defensive patterns

Strategy: fallback

Type guard

/** The widget's history fetch either works or 500s — no partial body. */
function isHistoryUnavailable(res) {
  return res.status === 500;
}

Try / catch

try {
  const { history } = await fetchEmbedHistory(embedId, sessionId);
} catch {
  // Public widget: never surface raw errors — start from empty history and let the user retry
  return { history: [] };
}

Prevention

When it happens

Trigger: A corrupt embed_chats row for that session (truncated JSON after a crash), database file locked by another process, storage volume read-only or full, schema drift after upgrading the server without migrating the DB.

Common situations: Embedded chat widgets on public sites failing silently after the server was hard-killed mid-write; multi-instance deployments sharing one storage dir; visiting an old session link after a major version upgrade.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18). Data as JSON: /api/errors/a8a78b6483aa38a1. Report an issue: GitHub.

Appendix: source

Thrown at server/endpoints/embed/index.js:87

  app.get(
    "/embed/:embedId/:sessionId",
    [validEmbedConfig],
    async (request, response) => {
      try {
        const { sessionId } = request.params;
        const embed = response.locals.embedConfig;
        const history = await EmbedChats.forEmbedByUser(
          embed.id,
          sessionId,
          null,
          null,
          true
        );

        response.status(200).json({ history: convertToChatHistory(history) });
      } catch (e) {
        console.error(e.message, e);
        response.sendStatus(500).end();
      }
    }
  );

  app.delete(
    "/embed/:embedId/:sessionId",
    [validEmbedConfig],
    async (request, response) => {
      try {
        const { sessionId } = request.params;
        const embed = response.locals.embedConfig;

        await EmbedChats.markHistoryInvalid(embed.id, sessionId);
        response.status(200).end();
      } catch (e) {
        console.error(e.message, e);
        response.sendStatus(500).end();
      }

View on GitHub (pinned to 3aec848f28)