{"record":{"id":"3b29bc6d86f31ee8","repo":"Mintplex-Labs/anything-llm","slug":"failed-to-parse-document-originalfilename","errorCode":null,"errorMessage":"Failed to parse document: ${originalFilename}","messagePattern":"Failed to parse document: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/telegramBot/utils/media.js","lineNumber":95,"sourceCode":"  const { CollectorApi } = require(\"../../collectorApi\");\n  const { hotdirPath } = require(\"../../files\");\n\n  if (!fs.existsSync(hotdirPath)) fs.mkdirSync(hotdirPath, { recursive: true });\n\n  const sanitizedName = originalFilename.replace(/[^a-zA-Z0-9._-]/g, \"_\");\n  const filename = `telegram-doc-${Date.now()}-${sanitizedName}`;\n  fs.writeFileSync(path.join(hotdirPath, filename), documentBuffer);\n\n  const collector = new CollectorApi();\n  if (!(await collector.online())) {\n    throw new Error(\n      \"Document processing is unavailable. The collector service is offline.\"\n    );\n  }\n\n  const result = await collector.parseDocument(filename);\n  if (!result?.success || !result.documents?.length) {\n    throw new Error(\n      result?.reason || `Failed to parse document: ${originalFilename}`\n    );\n  }\n\n  const text = result.documents.map((doc) => doc.pageContent).join(\"\\n\\n\");\n  return { text, filename: originalFilename };\n}\n\n/**\n * Download the largest photo from a Telegram photo array and return\n * it as an attachment object compatible with the LLM chat pipeline.\n * @param {TelegramBot} bot\n * @param {Array} photos - Telegram PhotoSize array (ascending size)\n * @returns {Promise<{name: string, mime: string, contentString: string}>}\n */\nasync function photoToAttachment(bot, photos) {\n  const largest = photos[photos.length - 1];\n  const buffer = await downloadTelegramFile(bot, largest.file_id);","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/telegramBot/utils/media.js#L77-L113","documentation":"Thrown by parseDocumentFromBuffer() when collector.parseDocument() returned but success is false or no documents were produced. The collector was online and accepted the file, but parsing itself failed (corrupt file, unsupported type, or parser crash). The message echoes originalFilename, or uses result.reason if the collector supplied one.","triggerScenarios":"Uploading a corrupt or password-protected PDF; a file type the collector has no parser for; a parser exception (e.g. PDF with malformed xref); an empty file that yields no text.","commonSituations":"User forwards a scanned PDF with no text layer and no OCR configured; an Office file in an unsupported format; a truncated upload; a parser library version regression in the collector image.","solutions":["Inspect result.reason from the collector for the specific parser error.","Try opening the file locally to confirm it is valid and not password-protected.","For scanned PDFs, enable/configure OCR in the collector.","Reply to the Telegram user with the originalFilename and ask for a re-send in a supported format."],"exampleFix":"// before\nconst text = result.documents.map(d => d.pageContent).join('\\n\\n');\n\n// after\nif (!result?.success || !result.documents?.length)\n  throw new Error(result?.reason || `Failed to parse document: ${originalFilename}`);\nconst text = result.documents.map(d => d.pageContent).join('\\n\\n');","handlingStrategy":"try-catch","validationCode":"const result = await collector.parseDocument(filename);\nif (!result?.success || !result.documents?.length)\n  throw new Error(result?.reason || `Failed to parse document: ${originalFilename}`);","typeGuard":null,"tryCatchPattern":"try {\n  const { text } = await parseDocumentFromBuffer(buffer, name);\n} catch (e) {\n  if (e.message.startsWith('Failed to parse document:'))\n    return ctx.reply(`Could not parse ${name}; try a different format.`);\n  throw e;\n}","preventionTips":["Surface result.reason to the user for actionable feedback.","Enable OCR for scanned PDFs in the collector.","Maintain a list of supported file types and validate the extension before parsing."],"tags":["telegram","collector","document-parsing","validation"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}