Skip to content

🐛 fix(toctree): crash with empty title in toctree#296

Merged
gaborbernat merged 1 commit intotox-dev:mainfrom
gaborbernat:fix-empty-title-toctree
Mar 16, 2026
Merged

🐛 fix(toctree): crash with empty title in toctree#296
gaborbernat merged 1 commit intotox-dev:mainfrom
gaborbernat:fix-empty-title-toctree

Conversation

@gaborbernat
Copy link
Member

When a page using :title: (empty) is included in a toctree, Sphinx's TocTreeCollector.process_doc crashes with list index out of range. This breaks documentation builds for projects like pyproject-fmt that place the CLI directive on a separate page referenced from a toctree.

The previous fix (2e8609c) changed paragraph() to section(""), but a section node without a title child still triggers the crash because the toctree collector expects all sections to have a title as their first child. Using container("") instead avoids this entirely — containers are generic block-level grouping elements that don't participate in document sectioning, so the toctree collector simply ignores them.

The test now mirrors the real-world scenario: the directive lives on a separate cli.rst page that is included via .. toctree:: from index.rst, which is the exact structure that triggers the bug.

@gaborbernat gaborbernat added the bug Something isn't working label Mar 16, 2026
Sphinx's TocTreeCollector expects all section nodes to have a title
child. When :title: was empty, the section("") node had no title child,
causing "list index out of range" when the page was included in a
toctree (e.g. pyproject-fmt's docs).

Using container instead of section avoids the toctree collector
entirely since containers don't participate in document sectioning.
@gaborbernat gaborbernat force-pushed the fix-empty-title-toctree branch from 047f03b to b131c6d Compare March 16, 2026 18:39
@gaborbernat gaborbernat enabled auto-merge (squash) March 16, 2026 18:39
@gaborbernat gaborbernat merged commit 9533451 into tox-dev:main Mar 16, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant