Mintplex-Labs/anything-llm · error

Failed to embed content

Error message

Failed to embed content

What it means

Catch-all 500 for POST /browser-extension/embed-content: anything thrown past the handled branches lands here. The most realistic throw is documents[0].location when the collector reported success:true with an empty documents array (TypeError reading 'location' of undefined), since processRawText itself never throws; otherwise it wraps Document.addDocuments throwing outright (DB open failure) or Telemetry.sendTelemetry (blocked outbound network). Server logs hold the actual stack.

Source

Thrown at server/endpoints/browserExtension.js:123

          return;
        }

        const { failedToEmbed = [], errors = [] } = await Document.addDocuments(
          workspace,
          [documents[0].location],
          user?.id
        );

        if (failedToEmbed.length > 0) {
          response.status(500).json({ success: false, error: errors[0] });
          return;
        }

        await Telemetry.sendTelemetry("browser_extension_embed_content");
        response.status(200).json({ success: true });
      } catch (error) {
        console.error(error);
        response.status(500).json({ error: "Failed to embed content" });
      }
    }
  );

  app.post(
    "/browser-extension/upload-content",
    [validBrowserExtensionApiKey],
    async (request, response) => {
      try {
        const { textContent, metadata } = reqBody(request);
        const Collector = new CollectorApi();
        const { success, reason } = await Collector.processRawText(
          textContent,
          metadata
        );

        if (!success) {
          response.status(500).json({ success: false, error: reason });

View on GitHub (pinned to 3aec848f28)

Solutions

  1. Read server logs - console.error prints the real stack; 'Cannot read properties of undefined (reading ...location)' confirms the empty-documents edge case.
  2. Restart server and collector together to eliminate version-drift payloads.
  3. If the stack points at Telemetry, allow outbound requests or set the telemetry-disable env var for the server.
  4. If you control the deployment, add the empty-documents guard shown in exampleFix.

Example fix

// before
const { failedToEmbed = [], errors = [] } = await Document.addDocuments(
  workspace,
  [documents[0].location],
  user?.id
);
// after
if (!success || !Array.isArray(documents) || documents.length === 0) {
  response.status(500).json({ success: false, error: "Collector returned no documents" });
  return;
}
const { failedToEmbed = [], errors = [] } = await Document.addDocuments(
  workspace,
  [documents[0].location],
  user?.id
);
Defensive patterns

Strategy: try-catch

Type guard

const hasDocuments = (r: unknown): r is { success: true; documents: { location: string }[] } =>
  typeof r === 'object' && r !== null && (r as any).success === true && Array.isArray((r as any).documents) && (r as any).documents.length > 0;

Try / catch

try {
  const res = await embedContent(apiKey, payload);
  if (!res.body?.success) logServerSide(res.requestId); // catch-all 500s need server logs
} catch (e) {
  // 500 'Failed to embed content' is opaque - surface the server's console.error stack to the operator
  throw new Error('Embed content failed; inspect AnythingLLM server logs for the thrown stack');
}

Prevention

When it happens

Trigger: Collector returns success with zero documents (edge-case extraction of the captured text); Telemetry.sendTelemetry throws on an air-gapped/egress-blocked server; addDocuments throws before returning its failedToEmbed structure (SQLite open/lock error).

Common situations: Hardened/air-gapped deployments without outbound telemetry access; collector/server version drift returning unexpected payload shapes; concurrent DB writers.

Related errors


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