Skip to content

Commit f1b1035

Browse files
Merge pull request #217 from adamtheturtle/exception-line
Add line numbers to more error messages
2 parents 60e371e + bfb8fe7 commit f1b1035

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/sphinx_notion/__init__.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,8 @@ def _(
461461
for child in node.children:
462462
if isinstance(child, nodes.title):
463463
table_no_titles_msg = (
464-
f"Table has a title '{child.astext()}', but Notion tables "
464+
f"Table has a title '{child.astext()}' on line "
465+
f"{child.line} in {child.source}, but Notion tables "
465466
"do not have titles."
466467
)
467468
# Ignore error which is about a type error, but we want to
@@ -472,8 +473,19 @@ def _(
472473
table_structure = _extract_table_structure(node=node)
473474

474475
if len(table_structure.header_rows) > 1:
476+
first_header_row = table_structure.header_rows[0]
477+
first_header_row_entry = first_header_row.children[0]
478+
first_header_row_paragraph = first_header_row_entry.children[0]
479+
first_header_row_line = first_header_row_paragraph.line
480+
last_header_row = table_structure.header_rows[-1]
481+
last_header_row_entry = last_header_row.children[0]
482+
last_header_row_paragraph = last_header_row_entry.children[0]
483+
last_header_row_line = last_header_row_paragraph.line
475484
table_multiple_header_rows_msg = (
476-
"Tables with multiple header rows are not supported."
485+
"Tables with multiple header rows are not supported. "
486+
f"First header row is on line {first_header_row_line} in "
487+
f"{first_header_row_paragraph.source}, last header row is on "
488+
f"line {last_header_row_line}"
477489
)
478490
raise ValueError(table_multiple_header_rows_msg)
479491

tests/test_integration.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,7 +1826,12 @@ def test_list_table_header_maximum_one_allowed(
18261826
- Cell a 2
18271827
"""
18281828

1829-
expected_message = r"^Tables with multiple header rows are not supported.$"
1829+
expected_message = (
1830+
r"^Tables with multiple header rows are not supported. "
1831+
r"First header row is on line 4 in "
1832+
rf"{re.escape(pattern=str(object=tmp_path / 'src' / 'index.rst'))}, "
1833+
r"last header row is on line 6"
1834+
)
18301835
with pytest.raises(expected_exception=ValueError, match=expected_message):
18311836
_assert_rst_converts_to_notion_objects(
18321837
rst_content=rst_content,
@@ -1941,7 +1946,9 @@ def test_list_table_with_title_error(
19411946
"""
19421947

19431948
expected_message = (
1944-
r"^Table has a title 'My Table Title', but Notion tables do not "
1949+
r"^Table has a title 'My Table Title' on line 1 in "
1950+
rf"{re.escape(pattern=str(object=tmp_path / 'src' / 'index.rst'))}, "
1951+
r"but Notion tables do not "
19451952
r"have titles.$"
19461953
)
19471954
with pytest.raises(expected_exception=ValueError, match=expected_message):

0 commit comments

Comments
 (0)