{"record":{"id":"d3c6650ca0ce1591","repo":"FlowiseAI/Flowise","slug":"failed-to-parse-word-file-error-instanceof-erro","errorCode":null,"errorMessage":"Failed to parse Word file: ${error instanceof Error ? error.message : 'Unknown error'}","messagePattern":"Failed to parse Word file: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/components/nodes/documentloaders/MicrosoftWord/WordLoader.ts","lineNumber":57,"sourceCode":"                // Split content by common page/section separators\n                const sections = this.splitIntoSections(data)\n\n                sections.forEach((sectionContent, index) => {\n                    if (sectionContent.trim()) {\n                        result.push({\n                            pageContent: sectionContent.trim(),\n                            metadata: {\n                                documentType: 'word',\n                                pageNumber: index + 1,\n                                ...metadata\n                            }\n                        })\n                    }\n                })\n            }\n        } catch (error) {\n            console.error('Error parsing Word file:', error)\n            throw new Error(`Failed to parse Word file: ${error instanceof Error ? error.message : 'Unknown error'}`)\n        }\n\n        return result\n    }\n\n    /**\n     * Split content into sections based on common patterns\n     * This is a heuristic approach since officeparser returns plain text\n     */\n    private splitIntoSections(content: string): string[] {\n        // Try to split by common section patterns\n        const sectionPatterns = [\n            /\\n\\s*Page\\s+\\d+/gi,\n            /\\n\\s*Section\\s+\\d+/gi,\n            /\\n\\s*Chapter\\s+\\d+/gi,\n            /\\n\\s*\\d+\\.\\s+/gi, // Numbered sections like \"1. \", \"2. \"\n            /\\n\\s*[A-Z][A-Z\\s]{2,}\\n/g, // ALL CAPS headings\n            /\\n\\s*_{5,}/g, // Long underscores as separators","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/nodes/documentloaders/MicrosoftWord/WordLoader.ts#L39-L75","documentation":"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.","triggerScenarios":"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.","commonSituations":"Renamed-file uploads; interrupted uploads producing partial files; encrypted documents; old binary .doc format; very large documents timing out.","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."],"exampleFix":"// before\nthrow new Error(`Failed to parse Word file: ${error instanceof Error ? error.message : 'Unknown error'}`)\n// after\nif (!raw || raw.length === 0) throw new Error('Word file is empty')\nthrow new Error('Failed to parse Word file', { cause: error })","handlingStrategy":"validation","validationCode":"function looksLikeOffice(buf) {\n  if (!buf || buf.length < 4) return false\n  return buf[0] === 0x50 && buf[1] === 0x4b && (buf[2] === 0x03 || buf[2] === 0x05 || buf[2] === 0x07)\n}\nif (!looksLikeOffice(raw)) throw new Error('File is not a valid Office (ZIP-based) document')","typeGuard":"function isNonEmptyBuffer(b) { return Buffer.isBuffer(b) && b.length > 0 }","tryCatchPattern":"try {\n  return await wordLoader.parse(raw, metadata)\n} catch (e) {\n  if (/Failed to parse Word file/.test(e.message)) {\n    throw new Error('Word file could not be parsed — verify it is a valid, unencrypted .docx', { cause: e })\n  }\n  throw e\n}","preventionTips":["Validate file magic bytes first.","Reject empty/truncated files.","Strip password protection.","Update officeparser."],"tags":["word","officeparser","file-parsing","binary"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}