Mintplex-Labs/anything-llm · error · Error
Failed to parse document: ${originalFilename}
Error message
Failed to parse document: ${originalFilename} What it means
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.
Source
Thrown at server/utils/telegramBot/utils/media.js:95
const { CollectorApi } = require("../../collectorApi");
const { hotdirPath } = require("../../files");
if (!fs.existsSync(hotdirPath)) fs.mkdirSync(hotdirPath, { recursive: true });
const sanitizedName = originalFilename.replace(/[^a-zA-Z0-9._-]/g, "_");
const filename = `telegram-doc-${Date.now()}-${sanitizedName}`;
fs.writeFileSync(path.join(hotdirPath, filename), documentBuffer);
const collector = new CollectorApi();
if (!(await collector.online())) {
throw new Error(
"Document processing is unavailable. The collector service is offline."
);
}
const result = await collector.parseDocument(filename);
if (!result?.success || !result.documents?.length) {
throw new Error(
result?.reason || `Failed to parse document: ${originalFilename}`
);
}
const text = result.documents.map((doc) => doc.pageContent).join("\n\n");
return { text, filename: originalFilename };
}
/**
* Download the largest photo from a Telegram photo array and return
* it as an attachment object compatible with the LLM chat pipeline.
* @param {TelegramBot} bot
* @param {Array} photos - Telegram PhotoSize array (ascending size)
* @returns {Promise<{name: string, mime: string, contentString: string}>}
*/
async function photoToAttachment(bot, photos) {
const largest = photos[photos.length - 1];
const buffer = await downloadTelegramFile(bot, largest.file_id);View on GitHub (pinned to 526360e320)
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.
Example fix
// before
const text = result.documents.map(d => d.pageContent).join('\n\n');
// after
if (!result?.success || !result.documents?.length)
throw new Error(result?.reason || `Failed to parse document: ${originalFilename}`);
const text = result.documents.map(d => d.pageContent).join('\n\n'); Defensive patterns
Strategy: try-catch
Validate before calling
const result = await collector.parseDocument(filename);
if (!result?.success || !result.documents?.length)
throw new Error(result?.reason || `Failed to parse document: ${originalFilename}`); Try / catch
try {
const { text } = await parseDocumentFromBuffer(buffer, name);
} catch (e) {
if (e.message.startsWith('Failed to parse document:'))
return ctx.reply(`Could not parse ${name}; try a different format.`);
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Document processing is unavailable. The collector service is
- Failed to transcribe audio.
- Internal Server Error
- Type "${type}" is not a valid type to sync.
- Invalid link provided
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/3b29bc6d86f31ee8.
Report an issue: GitHub.