{"record":{"id":"d6c5225479fdd33e","repo":"Mintplex-Labs/anything-llm","slug":"failed-to-fetch-document-content","errorCode":null,"errorMessage":"Failed to fetch document content","messagePattern":"Failed to fetch document content","errorType":"exception","errorClass":"Error","httpStatus":200,"severity":"error","filePath":"collector/extensions/resync/index.js","lineNumber":246,"sourceCode":" * Returns the content as a text string of the document.\n * @param {object} data - metadata from document (eg: chunkSource)\n * @param {import(\"../../middleware/setDataSigner\").ResponseWithSigner} response\n */\nasync function resyncPaperlessNgx({ chunkSource }, response) {\n  if (!chunkSource) throw new Error(\"Invalid source property provided\");\n  try {\n    const source = response.locals.encryptionWorker.expandPayload(chunkSource);\n    const {\n      PaperlessNgxLoader,\n    } = require(\"../../utils/extensions/PaperlessNgx/PaperlessNgxLoader\");\n    const loader = new PaperlessNgxLoader({\n      baseUrl: source.searchParams.get(\"baseUrl\"),\n      apiToken: source.searchParams.get(\"token\"),\n    });\n    const documentId = source.pathname.split(\"//\")[1];\n    const content = await loader.fetchDocumentContent(documentId);\n\n    if (!content) throw new Error(\"Failed to fetch document content\");\n    response.status(200).json({ success: true, content });\n  } catch (e) {\n    console.error(e);\n    response.status(200).json({\n      success: false,\n      content: null,\n    });\n  }\n}\n\nmodule.exports = {\n  link: resyncLink,\n  youtube: resyncYouTube,\n  confluence: resyncConfluence,\n  github: resyncGithub,\n  gitlab: resyncGitlab,\n  gitea: resyncGitea,\n  drupalwiki: resyncDrupalWiki,","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/collector/extensions/resync/index.js#L228-L264","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// documentId comes from source.pathname.split(\"//\")[1] — sanity check it pre-flight\nfunction safeDocumentId(pathname) {\n  const parts = String(pathname || \"\").split(\"//\");\n  const id = parts[1];\n  return (typeof id === \"string\" && id.length > 0) ? id : null;\n}\nconst documentId = safeDocumentId(source.pathname);\nif (!documentId) throw new Error(\"Could not derive documentId from chunkSource\");","typeGuard":null,"tryCatchPattern":"try { await resyncPaperlessNgx({ chunkSource }, response); }\ncatch (e) {\n  if (e.message === \"Failed to fetch document content\") {\n    // could be: token revoked, document deleted, or empty OCR\n    verifyPaperlessTokenAndDocument();\n  } else throw e;\n}","preventionTips":["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."],"tags":["auth","network","resync","paperless-ngx"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}