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
- Verify the document still exists in Paperless-ngx and the API token can read it.
- Check that source.pathname after expandPayload still contains the expected //documentId segment.
- Re-scrape the Paperless-ngx library to mint a fresh chunkSource with a valid token.
- 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
- Re-scrape when the Paperless-ngx token rotates so chunkSource is fresh.
- Confirm the documentId segment survives chunkSource pathname shape changes.
- Treat empty-content as a soft failure (skip) rather than overwriting the stored text with null.
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
- Failed to sync Confluence page content. ${reason}
- Failed to sync GitHub file content. ${reason}
- Failed to sync GitLab file content. ${reason}
- Failed to sync Gitea file content. ${reason}
- Failed to sync link content. ${reason}
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/d6c5225479fdd33e.
Report an issue: GitHub.