Skip to content

Commit afae11a

Browse files
committed
catch syntax error for options and defaults
1 parent b160568 commit afae11a

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

snooty/parser.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,19 @@ def handle_composable(self, node: n.ComposableDirective) -> None:
939939
)
940940
continue
941941
ordered_spec_composables.append(composable_from_spec)
942-
specified_default_id = default_ids[index]
942+
try:
943+
specified_default_id = default_ids[index]
944+
except IndexError:
945+
# error to be verbose about default ids not matching up with option ids
946+
self.diagnostics.append(
947+
InvalidChildCount(
948+
"composable-tutorial",
949+
"defaults",
950+
str(len(option_ids)),
951+
node.start[0],
952+
)
953+
)
954+
continue
943955
allowed_values_dict = {
944956
option.id: option for option in composable_from_spec.options
945957
}

snooty/test_postprocess.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
GuideAlreadyHasChapter,
1919
InvalidChapter,
2020
InvalidChild,
21+
InvalidChildCount,
2122
InvalidContextError,
2223
InvalidIAEntry,
2324
InvalidIALinkedData,
@@ -4272,6 +4273,26 @@ def test_composable_tutorial_errors() -> None:
42724273
MissingChild,
42734274
]
42744275

4276+
with make_test(
4277+
{
4278+
Path(
4279+
"source/index.txt"
4280+
): """
4281+
.. composable-tutorial::
4282+
:options: interface, language, cluster-topology, cloud-provider
4283+
:defaults: driver, None, repl
4284+
4285+
.. selected-content::
4286+
:selections: driver, None, repl
4287+
"""
4288+
}
4289+
) as result:
4290+
diagnostics = result.diagnostics[FileId("index.txt")]
4291+
assert len(diagnostics) == 1
4292+
assert [type(d) for d in diagnostics] == [
4293+
InvalidChildCount,
4294+
]
4295+
42754296

42764297
def test_composable_headings() -> None:
42774298
with make_test(

0 commit comments

Comments
 (0)