You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR fixes a ValueError: not enough values to unpack (expected 2, got 1) crash that occurred when a .. tab-set:: directive contained invalid content (non-tab-item children).
Changes Made
1. Modified TabSetDirective.run_with_defaults() in sphinx_design/tabs.py (lines 38-53):
Changed from break to continue to warn about ALL invalid children, not just the first one
Added filtering to remove invalid children from tab_set.children
Valid tab-item directives are preserved in a new list and reassigned
2. Added defensive validation in TabSetHtmlTransform.run() in sphinx_design/tabs.py (lines 247-256):
Added check to skip non-tab-item children that may have slipped through
Added validation to ensure tab-item has exactly 2 children before unpacking
Logs appropriate warnings for malformed directives
3. Added comprehensive test in tests/test_misc.py:
Tests that tab-set with invalid children does not crash
Verifies warnings are properly logged
Confirms valid tab items are still processed and rendered correctly
Behavior After Fix
✅ Before: Sphinx-design crashed with ValueError when encountering invalid content in a tab-set
✅ After: Sphinx-design logs warnings for each invalid child and continues to render valid tab-items
Example input with invalid content:
.. tab-set::
.. tab-item:: A
A content
foo <-- Invalid content
.. tab-item:: B
B content
Result: Both valid tabs (A and B) render correctly, and a warning is logged for the invalid "foo" content.
Visual Verification
The fix was manually tested with a document containing invalid content between tab items:
All three valid tab items render and function correctly despite invalid content in the source.
Tests
All 110 tests pass, including the new test specifically for this issue:
✅ test_tab_set_with_invalid_children - New test reproducing and validating the fix
✅ All existing tests continue to pass
✅ All pre-commit hooks pass
Checklist
Understand the issue and explore the codebase
Create tests to reproduce the ValueError bug
Fix TabSetDirective.run_with_defaults() to filter invalid children
Add defensive validation in TabSetHtmlTransform.run()
Sphinx-design crashes with a ValueError: not enough values to unpack (expected 2, got 1) when a .. tab-set:: directive contains something other than .. tab-item:: directives.
Reproduction
Tab Test document
=================
.. tab-set::
.. tab-item:: A
A content
foo <-- This line causes the crash
.. tab-item:: B
B content
Root Cause
The problem is in sphinx_design/tabs.py:
In TabSetDirective.run_with_defaults() (lines 38-47): When a non-tab-item child is found, the code logs a warning but only breaks after the first invalid child. It does NOT remove the invalid children from tab_set.children.
In TabSetHtmlTransform.run() (line 244): The code assumes all children are valid tab-item components with exactly 2 children:
tab_label, tab_content=tab_item.children
When an invalid child (like a text node) is encountered, it doesn't have 2 children, causing the unpacking error.
Required Fix
1. Modify TabSetDirective.run_with_defaults() in sphinx_design/tabs.py:
Change the loop that validates children to:
Use continue instead of break to warn about ALL invalid children, not just the first
Filter out invalid children so only valid tab-item components remain in tab_set.children
The current code:
foritemintab_set.children:
ifnotis_component(item, "tab-item"):
LOGGER.warning(
f"All children of a 'tab-set' "f"should be 'tab-item' [{WARNING_TYPE}.tab]",
location=item,
type=WARNING_TYPE,
subtype="tab",
)
breakif"sync_id"initem.children[0]:
item.children[0]["sync_group"] =self.options.get("sync-group", "tab")
return [tab_set]
Should become:
valid_children= []
foritemintab_set.children:
ifnotis_component(item, "tab-item"):
LOGGER.warning(
f"All children of a 'tab-set' "f"should be 'tab-item' [{WARNING_TYPE}.tab]",
location=item,
type=WARNING_TYPE,
subtype="tab",
)
continue# Skip invalid children instead of breakingif"sync_id"initem.children[0]:
item.children[0]["sync_group"] =self.options.get("sync-group", "tab")
valid_children.append(item)
tab_set.children=valid_childrenreturn [tab_set]
2. Add defensive validation in TabSetHtmlTransform.run() in sphinx_design/tabs.py:
In the loop at line 242, add a check before unpacking to handle any edge cases:
Note: You'll need to import is_component at the top of the TabSetHtmlTransform.run() method if it's not already available in that scope (it should be available since it's imported from .shared).
Expected Behavior After Fix
Sphinx-design should NOT crash when invalid content is inside a tab-set
A warning should be logged for each invalid child
Valid tab-item directives should still be processed and rendered correctly
The warning should include accurate location information
This pull request was created from Copilot chat.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
CopilotAI
changed the title
[WIP] Fix ValueError in tab-set directive handlingFix ValueError crash when tab-set contains non-tab-item childrenJan 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix tab-set crash with invalid children
Fixes#243
Summary
This PR fixes a
ValueError: not enough values to unpack (expected 2, got 1)crash that occurred when a.. tab-set::directive contained invalid content (non-tab-itemchildren).Changes Made
1. Modified
TabSetDirective.run_with_defaults()insphinx_design/tabs.py(lines 38-53):breaktocontinueto warn about ALL invalid children, not just the first onetab_set.childrentab-itemdirectives are preserved in a new list and reassigned2. Added defensive validation in
TabSetHtmlTransform.run()insphinx_design/tabs.py(lines 247-256):tab-itemchildren that may have slipped throughtab-itemhas exactly 2 children before unpacking3. Added comprehensive test in
tests/test_misc.py:Behavior After Fix
✅ Before: Sphinx-design crashed with
ValueErrorwhen encountering invalid content in a tab-set✅ After: Sphinx-design logs warnings for each invalid child and continues to render valid tab-items
Example input with invalid content:
Result: Both valid tabs (A and B) render correctly, and a warning is logged for the invalid "foo" content.
Visual Verification
The fix was manually tested with a document containing invalid content between tab items:
All three valid tab items render and function correctly despite invalid content in the source.
Tests
All 110 tests pass, including the new test specifically for this issue:
test_tab_set_with_invalid_children- New test reproducing and validating the fixChecklist
TabSetDirective.run_with_defaults()to filter invalid childrenTabSetHtmlTransform.run()Original prompt
This pull request was created from Copilot chat.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.