infiniflow/ragflow · error · Exception

TXT generation failed: {str(e)}

Error message

TXT generation failed: {str(e)}

What it means

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.

Source

Thrown at agent/component/docs_generator.py:633

    def _generate_docx(self, content: str) -> tuple[str, bytes]:
        try:
            file_path, _ = self._generate_pandoc_binary_output(
                content,
                "docx",
                "docx",
                include_timestamp_in_body=False,
                extra_args=["--standalone"],
            )
            return self._decorate_docx(file_path)
        except Exception as e:
            raise Exception(f"DOCX generation failed: {str(e)}")

    def _generate_txt(self, content: str) -> tuple[str, bytes]:
        try:
            return self._generate_pandoc_text_output(content, "plain", "txt")
        except Exception as e:
            raise Exception(f"TXT generation failed: {str(e)}")

    def _generate_markdown(self, content: str) -> tuple[str, bytes]:
        try:
            return self._generate_pandoc_text_output(content, "markdown", "md")
        except Exception as e:
            raise Exception(f"Markdown generation failed: {str(e)}")

    def _generate_html(self, content: str) -> tuple[str, bytes]:
        try:
            return self._generate_pandoc_text_output(content, "html", "html")
        except Exception as e:
            raise Exception(f"HTML generation failed: {str(e)}")

View on GitHub (pinned to 554fb1133a)

Solutions

  1. Check the inner message after 'TXT generation failed:' — 'No pandoc was found' means install pandoc or pypandoc-binary
  2. Verify pandoc on the worker's PATH: pandoc --version
  3. Sanitize/validate the content string is valid UTF-8 before passing it in
  4. Reproduce manually: pandoc -f markdown -t plain input.md

Example fix

# before
pip install pypandoc            # wrapper only, no binary

# after
pip install pypandoc-binary      # or apt-get install pandoc
Defensive patterns

Strategy: try-catch

Validate before calling

import shutil

def txt_prerequisites_ok():
    return shutil.which('pandoc') is not None

Try / catch

try:
    file_path, file_bytes = generator._generate_txt(content)
except Exception as e:
    inner = str(e).removeprefix('TXT generation failed: ')
    if 'No pandoc was found' in inner:
        raise RuntimeError('TXT output needs pandoc: apt-get install pandoc or pip install pypandoc-binary') from e
    logger.error('TXT generation root cause: %s', inner)
    raise

Prevention

When it happens

Trigger: 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').

Common situations: 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).

Related errors


AI-assisted analysis of infiniflow/ragflow@554fb1133a (2026-08-15). Data as JSON: /api/errors/2c04cd08f13e9767. Report an issue: GitHub.