Mintplex-Labs/anything-llm · error · Error

Failed to fetch document content

Error message

Failed to fetch document content

What it means

Thrown by resyncPaperlessNgx in collector/extensions/resync/index.js:246 when loader.fetchDocumentContent(documentId) returns a falsy value (null, undefined, empty string). Unlike the other resync handlers this is a content-presence check rather than a {success, reason} envelope check — PaperlessNgxLoader.fetchDocumentContent returns the raw text (or null) instead of a result object. Handler catches and answers HTTP 200 with success:false, content:null.

Source

Thrown at collector/extensions/resync/index.js:246

 * Returns the content as a text string of the document.
 * @param {object} data - metadata from document (eg: chunkSource)
 * @param {import("../../middleware/setDataSigner").ResponseWithSigner} response
 */
async function resyncPaperlessNgx({ chunkSource }, response) {
  if (!chunkSource) throw new Error("Invalid source property provided");
  try {
    const source = response.locals.encryptionWorker.expandPayload(chunkSource);
    const {
      PaperlessNgxLoader,
    } = require("../../utils/extensions/PaperlessNgx/PaperlessNgxLoader");
    const loader = new PaperlessNgxLoader({
      baseUrl: source.searchParams.get("baseUrl"),
      apiToken: source.searchParams.get("token"),
    });
    const documentId = source.pathname.split("//")[1];
    const content = await loader.fetchDocumentContent(documentId);

    if (!content) throw new Error("Failed to fetch document content");
    response.status(200).json({ success: true, content });
  } catch (e) {
    console.error(e);
    response.status(200).json({
      success: false,
      content: null,
    });
  }
}

module.exports = {
  link: resyncLink,
  youtube: resyncYouTube,
  confluence: resyncConfluence,
  github: resyncGithub,
  gitlab: resyncGitlab,
  gitea: resyncGitea,
  drupalwiki: resyncDrupalWiki,

View on GitHub (pinned to 526360e320)

Solutions

  1. Verify the document still exists in Paperless-ngx and the API token can read it.
  2. Check that source.pathname after expandPayload still contains the expected //documentId segment.
  3. Re-scrape the Paperless-ngx library to mint a fresh chunkSource with a valid token.
  4. If the document genuinely has no text, accept the empty result or fix OCR in Paperless-ngx.
Defensive patterns

Strategy: try-catch

Validate before calling

// documentId comes from source.pathname.split("//")[1] — sanity check it pre-flight
function safeDocumentId(pathname) {
  const parts = String(pathname || "").split("//");
  const id = parts[1];
  return (typeof id === "string" && id.length > 0) ? id : null;
}
const documentId = safeDocumentId(source.pathname);
if (!documentId) throw new Error("Could not derive documentId from chunkSource");

Try / catch

try { await resyncPaperlessNgx({ chunkSource }, response); }
catch (e) {
  if (e.message === "Failed to fetch document content") {
    // could be: token revoked, document deleted, or empty OCR
    verifyPaperlessTokenAndDocument();
  } else throw e;
}

Prevention

When it happens

Trigger: Resyncing a Paperless-ngx document whose documentId (parsed from source.pathname.split("//")[1]) is wrong or empty; the document was deleted in Paperless-ngx; the API token lost read permission; OCR returned no extractable text; baseUrl token revoked so the loader returned null.

Common situations: documentId parsing produced undefined (chunkSource pathname shape changed); document deleted/archived in Paperless-ngx; token rotated since original scrape; scanned document with no OCR data.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13). Data as JSON: /api/errors/d6c5225479fdd33e. Report an issue: GitHub.