Skip to content

Commit 4a130a3

Browse files
committed
only show first error
1 parent 6adc78c commit 4a130a3

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

quartodoc/autosummary.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,10 @@ def load_layout(self, sections: dict, package: str):
451451
try:
452452
return layout.Layout(sections=sections, package=package)
453453
except ValidationError as e:
454-
msg = 'Configuration error(s) for YAML:\n - '
455-
msg += '\n - '.join([fmt(err) for err in e.errors() if fmt(err)])
454+
msg = 'Configuration error for YAML:\n - '
455+
errors = [fmt(err) for err in e.errors() if fmt(err)]
456+
first_error = errors[0] # we only want to show one error at a time b/c it is confusing otherwise
457+
msg += first_error
456458
raise ValueError(msg) from None
457459

458460
# building ----------------------------------------------------------------

quartodoc/tests/test_validation.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
def test_valid_yaml():
4747
Builder(sections=EXAMPLE_SECTIONS, package='quartodoc')
4848

49-
5049
def test_missing_title():
5150
sections = copy.deepcopy(EXAMPLE_SECTIONS)
5251
del sections[0]['title']
@@ -64,8 +63,16 @@ def test_missing_desc():
6463

6564
assert '- Missing field `desc` for element 2 in the list for `sections`' in str(e.value)
6665

67-
def test_missing_name_contents():
68-
# This is failing on purpose, will fix in pair programming
66+
def test_missing_name_contents_1():
6967
sections = copy.deepcopy(EXAMPLE_SECTIONS)
7068
del sections[2]['contents'][0]['name']
71-
Builder(sections=sections, package='quartodoc')
69+
with pytest.raises(ValueError) as e:
70+
Builder(sections=sections, package='quartodoc')
71+
assert '- Missing field `name` for element 0 in the list for `contents` located in element 2 in the list for `sections`' in str(e.value)
72+
73+
def test_missing_name_contents_2():
74+
sections = copy.deepcopy(EXAMPLE_SECTIONS)
75+
del sections[1]['contents'][0]['name']
76+
with pytest.raises(ValueError) as e:
77+
Builder(sections=sections, package='quartodoc')
78+
assert '- Missing field `name` for element 0 in the list for `contents` located in element 1 in the list for `sections`' in str(e.value)

quartodoc/validation.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ def fmt(err:dict):
1414
msg += f" from root level: `{err['loc'][0]}`"
1515
elif len(err['loc']) == 3:
1616
msg += f" `{err['loc'][2]}` for element {err['loc'][1]} in the list for `{err['loc'][0]}`"
17-
17+
elif len(err['loc']) == 5:
18+
msg += f" `{err['loc'][4]}` for element {err['loc'][3]} in the list for `{err['loc'][2]}` located in element {err['loc'][1]} in the list for `{err['loc'][0]}`"
19+
elif len(err['loc']) == 6 and err['loc'][4] == 'Auto':
20+
msg += f" `{err['loc'][5]}` for element {err['loc'][3]} in the list for `{err['loc'][2]}` located in element {err['loc'][1]} in the list for `{err['loc'][0]}`"
1821
else:
19-
msg += str(err['msg'])
22+
msg += str(err)
2023
return msg

0 commit comments

Comments
 (0)