FlowiseAI/Flowise · error · Error
Failed to parse Word file: ${error instanceof Error ? error.
Error message
Failed to parse Word file: ${error instanceof Error ? error.message : 'Unknown error'} What it means
Thrown by WordLoader.parse when officeparser's parseOfficeAsync rejects while extracting text from a Word Buffer. Same shape as the PowerPoint loader: message surfaces officeparser's error text. Original stack is not chained.
Source
Thrown at packages/components/nodes/documentloaders/MicrosoftWord/WordLoader.ts:57
// Split content by common page/section separators
const sections = this.splitIntoSections(data)
sections.forEach((sectionContent, index) => {
if (sectionContent.trim()) {
result.push({
pageContent: sectionContent.trim(),
metadata: {
documentType: 'word',
pageNumber: index + 1,
...metadata
}
})
}
})
}
} catch (error) {
console.error('Error parsing Word file:', error)
throw new Error(`Failed to parse Word file: ${error instanceof Error ? error.message : 'Unknown error'}`)
}
return result
}
/**
* Split content into sections based on common patterns
* This is a heuristic approach since officeparser returns plain text
*/
private splitIntoSections(content: string): string[] {
// Try to split by common section patterns
const sectionPatterns = [
/\n\s*Page\s+\d+/gi,
/\n\s*Section\s+\d+/gi,
/\n\s*Chapter\s+\d+/gi,
/\n\s*\d+\.\s+/gi, // Numbered sections like "1. ", "2. "
/\n\s*[A-Z][A-Z\s]{2,}\n/g, // ALL CAPS headings
/\n\s*_{5,}/g, // Long underscores as separatorsView on GitHub (pinned to abe4a8601a)
Solutions
- Confirm the file opens in Word/LibreOffice and is a supported format.
- Re-upload to rule out truncation.
- Remove document password protection.
- Update officeparser.
- Preserve cause on re-throw.
Example fix
// before
throw new Error(`Failed to parse Word file: ${error instanceof Error ? error.message : 'Unknown error'}`)
// after
if (!raw || raw.length === 0) throw new Error('Word file is empty')
throw new Error('Failed to parse Word file', { cause: error }) Defensive patterns
Strategy: validation
Validate before calling
function looksLikeOffice(buf) {
if (!buf || buf.length < 4) return false
return buf[0] === 0x50 && buf[1] === 0x4b && (buf[2] === 0x03 || buf[2] === 0x05 || buf[2] === 0x07)
}
if (!looksLikeOffice(raw)) throw new Error('File is not a valid Office (ZIP-based) document') Type guard
function isNonEmptyBuffer(b) { return Buffer.isBuffer(b) && b.length > 0 } Try / catch
try {
return await wordLoader.parse(raw, metadata)
} catch (e) {
if (/Failed to parse Word file/.test(e.message)) {
throw new Error('Word file could not be parsed — verify it is a valid, unencrypted .docx', { cause: e })
}
throw e
} Prevention
- Validate file magic bytes first.
- Reject empty/truncated files.
- Strip password protection.
- Update officeparser.
When it happens
Trigger: File is not a valid .doc/.docx (renamed extension); file is corrupt or truncated; password-protected/encrypted document; officeparser cannot handle legacy binary .doc in the installed version; empty Buffer.
Common situations: Renamed-file uploads; interrupted uploads producing partial files; encrypted documents; old binary .doc format; very large documents timing out.
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
AI-assisted analysis of FlowiseAI/Flowise@abe4a8601a (2026-08-12).
Data as JSON: /api/errors/d3c6650ca0ce1591.
Report an issue: GitHub.