{"record":{"id":"adfc71ec016c6fa2","repo":"infiniflow/ragflow","slug":"document-file-is-empty","errorCode":null,"errorMessage":"Document file is empty","messagePattern":"Document file is empty","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"agent/component/docs_generator.py","lineNumber":120,"sourceCode":"                    mime_type = \"application/pdf\"\n                elif output_format == \"docx\":\n                    file_path, file_bytes = self._generate_docx(content)\n                    mime_type = \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\"\n                elif output_format == \"txt\":\n                    file_path, file_bytes = self._generate_txt(content)\n                    mime_type = \"text/plain\"\n                elif output_format == \"markdown\":\n                    file_path, file_bytes = self._generate_markdown(content)\n                    mime_type = \"text/markdown\"\n                elif output_format == \"html\":\n                    file_path, file_bytes = self._generate_html(content)\n                    mime_type = \"text/html\"\n                else:\n                    raise Exception(f\"Unsupported output format: {output_format}\")\n\n                filename = os.path.basename(file_path)\n                if not file_bytes:\n                    raise Exception(\"Document file is empty\")\n\n                file_size = len(file_bytes)\n                file_base64 = base64.b64encode(file_bytes).decode(\"utf-8\")\n                doc_id = get_uuid()\n                settings.STORAGE_IMPL.put(self._canvas.get_tenant_id(), doc_id, file_bytes)\n\n                logging.info(\n                    \"Successfully generated %s: %s (Size: %s bytes)\",\n                    output_format.upper(),\n                    filename,\n                    file_size,\n                )\n\n                download_info = {\n                    \"doc_id\": doc_id,\n                    \"filename\": filename,\n                    \"mime_type\": mime_type,\n                    \"size\": file_size,","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/agent/component/docs_generator.py#L102-L138","documentation":"Raised in the DocGenerator message flow (agent/component/docs_generator.py) after a format generator returns: the produced file bytes are empty (falsy). It guards against writing an empty blob to storage and returning a broken document id. Usually a symptom of an upstream pandoc/conversion step producing nothing rather than a configuration error.","triggerScenarios":"Running DocGenerator with content that converts to zero bytes (e.g. whitespace-only input combined with a template), or a pandoc invocation that silently outputs an empty file for the chosen format; also storage decorators returning empty on failure. The check is `if not file_bytes: raise Exception('Document file is empty')` after _generate_pdf/docx/txt/markdown/html.","commonSituations":"Content parameter resolving to an empty/unrendered template variable (e.g. a reference like {input} that produced nothing); pandoc version quirks emitting empty output for exotic markdown; edge-case formats (html with only stripped tags).","solutions":["Verify the component's content input actually resolves to non-empty text at run time (log it just before generation)","If content is fine, test the same markdown through pandoc directly to see whether the toolchain produces empty output, and update/replace pandoc","Ensure upstream components (LLM/generate) succeeded and their output is wired into DocGenerator's content parameter"],"exampleFix":"# before\nself.content = \"{{gen_output}}\"   # unresolved placeholder -> empty render\n\n# after\nself.content = component_input   # verified non-empty string from upstream","handlingStrategy":"try-catch","validationCode":"content = resolve_input(param.content)\nif not content or not content.strip():\n    raise ValueError('DocGenerator content resolved to empty text; check upstream component wiring')","typeGuard":null,"tryCatchPattern":"try:\n    result = doc_generator.run(...)\nexcept Exception as e:\n    if str(e) == 'Document file is empty':\n        log_upstream_content(param.content)\n        raise RuntimeError('Document generation produced no bytes; verify content input and pandoc install') from e\n    raise","preventionTips":["Assert the content parameter resolves to non-empty text before running DocGenerator","Log the resolved content at debug level during canvas development","Keep pandoc healthy — empty pandoc output is a common root cause"],"tags":["agent-component","doc-generator","pandoc","runtime"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}