Textualize/textual · error · ParseError

end of file reached

Error message

end of file reached

What it means

Raised by Parser.feed when more data is pushed into the tokenizer after it has already been signaled that input ended (an empty data chunk sets _eof). It indicates a state-machine misuse of the incremental parser rather than malformed input.

Source

Thrown at src/textual/_parser.py:78

            self._timeout_time = None
            self._awaiting = self._gen.throw(ParseTimeout())
            while self._tokens:
                yield self._tokens.popleft()

    def feed(self, data: str) -> Iterable[T]:
        """Feed data to be parsed.

        Args:
            data: Data to parser.

        Raises:
            ParseError: If the data could not be parsed.

        Yields:
            T: A generic data type.
        """
        if self._eof:
            raise ParseError("end of file reached") from None

        tokens = self._tokens
        popleft = tokens.popleft

        if not data:
            self._eof = True
            try:
                self._gen.throw(ParseEOF())
            except StopIteration:
                pass
            while tokens:
                yield popleft()
            return

        pos = 0
        data_size = len(data)

        while tokens:

View on GitHub (pinned to 06dbeef4bb)

Solutions

  1. Do not pass an empty string to feed unless you truly intend to end input; skip falsy chunks before feeding
  2. Use a fresh Parser instance for each new document/stream
  3. If streaming from a file/network, only send a final empty/EOF signal once, at true end of stream

Example fix

# before
for chunk in chunks:
    parser.feed(chunk)  # chunk may be ''

# after
for chunk in chunks:
    if chunk:
        parser.feed(chunk)
parser.feed("")  # signal EOF exactly once
Defensive patterns

Strategy: validation

Validate before calling

if parser._eof:
    parser = Parser(...)  # reset instead of feeding

Try / catch

try:
    parser.feed(data)
except ParseError:
    parser = Parser(...)  # restart with fresh state

Prevention

When it happens

Trigger: Calling feed('') once (which sets self._eof = True) and then calling feed(data) again on the same Parser instance.

Common situations: Tokenizing CSS/content in a loop where an empty chunk terminates input accidentally; reusing a single Parser object across multiple documents; feeding leftover bytes after signaling EOF.


AI-assisted analysis of Textualize/textual@06dbeef4bb (2026-08-27). Data as JSON: /api/errors/89bb6a4eefebc479. Report an issue: GitHub.