Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/src/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ These release notes are based on
sphinx-codeautolink adheres to
`Semantic Versioning <https://semver.org>`_.

Unreleased
----------
- Fix attribute and call after walrus leading parser error (:issue:`174`)
- Improve error message on uncaught parsing errors (:issue:`177`)

0.17.0 (2025-02-18)
-------------------
Added
Expand Down
9 changes: 8 additions & 1 deletion src/sphinx_codeautolink/extension/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def visit_literal_block(self, node: nodes.literal_block):
"""Visit a generic literal block."""
return self.parse_source(node, node.get("language", self.highlight_lang))

def parse_source( # noqa: C901
def parse_source( # noqa: C901,PLR0912
self, node: nodes.literal_block | nodes.doctest_block, language: str | None
) -> None:
"""Analyse Python code blocks."""
Expand Down Expand Up @@ -258,6 +258,12 @@ def parse_source( # noqa: C901
msg = self._parsing_error_msg(e, language, show_source)
logger.warning(msg, type=warn_type, subtype="parse_block", location=node)
return
except Exception as e:
show_source = self._format_source_for_error(
self.global_preface, self.concat_sources, prefaces, transform.source
)
msg = self._parsing_error_msg(e, language, show_source)
raise type(e)(msg) from e

if prefaces or self.concat_sources or self.global_preface:
concat_lens = [s.count("\n") + 1 for s in self.concat_sources]
Expand Down Expand Up @@ -302,6 +308,7 @@ def _parsing_error_msg(self, error: Exception, language: str, source: str) -> st
str(error) + f" in document {self.current_document!r}",
f"Parsed source in `{language}` block:",
source,
"",
]
)

Expand Down
Loading
Loading