{"record":{"id":"2c04cd08f13e9767","repo":"infiniflow/ragflow","slug":"txt-generation-failed-str-e","errorCode":null,"errorMessage":"TXT generation failed: {str(e)}","messagePattern":"TXT generation failed: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"agent/component/docs_generator.py","lineNumber":633,"sourceCode":"\n    def _generate_docx(self, content: str) -> tuple[str, bytes]:\n        try:\n            file_path, _ = self._generate_pandoc_binary_output(\n                content,\n                \"docx\",\n                \"docx\",\n                include_timestamp_in_body=False,\n                extra_args=[\"--standalone\"],\n            )\n            return self._decorate_docx(file_path)\n        except Exception as e:\n            raise Exception(f\"DOCX generation failed: {str(e)}\")\n\n    def _generate_txt(self, content: str) -> tuple[str, bytes]:\n        try:\n            return self._generate_pandoc_text_output(content, \"plain\", \"txt\")\n        except Exception as e:\n            raise Exception(f\"TXT generation failed: {str(e)}\")\n\n    def _generate_markdown(self, content: str) -> tuple[str, bytes]:\n        try:\n            return self._generate_pandoc_text_output(content, \"markdown\", \"md\")\n        except Exception as e:\n            raise Exception(f\"Markdown generation failed: {str(e)}\")\n\n    def _generate_html(self, content: str) -> tuple[str, bytes]:\n        try:\n            return self._generate_pandoc_text_output(content, \"html\", \"html\")\n        except Exception as e:\n            raise Exception(f\"HTML generation failed: {str(e)}\")\n","sourceCodeStart":615,"sourceCodeEnd":646,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/agent/component/docs_generator.py#L615-L646","documentation":"Catch-all wrapper thrown by DocGenerator._generate_txt (agent/component/docs_generator.py): the pandoc text conversion markdown->plain raised, and it is re-raised as Exception('TXT generation failed: <inner message>'). TXT is the simplest path, so failures almost always mean pandoc itself is unavailable or the input markdown triggers a parser error.","triggerScenarios":"Running DocGenerator with output_format 'txt' when pypandoc cannot find the pandoc binary (OSError: No pandoc was found), pandoc exits non-zero on malformed input, or the output write path fails. Raised from the except around _generate_pandoc_text_output(content, 'plain', 'txt').","commonSituations":"Deployments that installed pypandoc (the wrapper) but not pandoc or pypandoc-binary; PATH differences between the shell used to install and the service runtime; content with encoding issues (lone surrogates, invalid UTF-8).","solutions":["Check the inner message after 'TXT generation failed:' — 'No pandoc was found' means install pandoc or pypandoc-binary","Verify pandoc on the worker's PATH: pandoc --version","Sanitize/validate the content string is valid UTF-8 before passing it in","Reproduce manually: pandoc -f markdown -t plain input.md"],"exampleFix":"# before\npip install pypandoc            # wrapper only, no binary\n\n# after\npip install pypandoc-binary      # or apt-get install pandoc","handlingStrategy":"try-catch","validationCode":"import shutil\n\ndef txt_prerequisites_ok():\n    return shutil.which('pandoc') is not None","typeGuard":null,"tryCatchPattern":"try:\n    file_path, file_bytes = generator._generate_txt(content)\nexcept Exception as e:\n    inner = str(e).removeprefix('TXT generation failed: ')\n    if 'No pandoc was found' in inner:\n        raise RuntimeError('TXT output needs pandoc: apt-get install pandoc or pip install pypandoc-binary') from e\n    logger.error('TXT generation root cause: %s', inner)\n    raise","preventionTips":["Check pandoc availability before offering txt output","Validate content is non-empty valid UTF-8 before generation","Keep pandoc versions consistent between dev and production images"],"tags":["doc-generator","pandoc","runtime","error-wrapping"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}