Skip to content

Commit

Permalink
Handle exceptions for get_node_source and get_node_line
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Jan 10, 2023
1 parent dcb4429 commit 31162a9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 4 additions & 1 deletion sphinx/builders/linkcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,10 @@ def add_uri(uri: str, node: nodes.Element) -> None:
if newuri:
uri = newuri

lineno = get_node_line(node)
try:
lineno = get_node_line(node)
except ValueError:
lineno = None
uri_info = Hyperlink(uri, self.env.docname, lineno)
if uri not in hyperlinks:
hyperlinks[uri] = uri_info
Expand Down
10 changes: 7 additions & 3 deletions sphinx/util/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,10 @@ def apply_source_workaround(node: Element) -> None:
))):
logger.debug('[i18n] PATCH: %r to have source and line: %s',
get_full_module_name(node), repr_domxml(node))
node.source = get_node_source(node) or ''
try:
node.source = get_node_source(node)
except ValueError:
node.source = ''
node.line = 0 # need fix docutils to get `node.line`
return

Expand Down Expand Up @@ -561,8 +564,9 @@ def set_role_source_info(inliner: Inliner, lineno: int, node: Node) -> None:


def copy_source_info(src: Element, dst: Element) -> None:
dst.source = get_node_source(src)
dst.line = get_node_line(src)
with contextlib.suppress(ValueError):
dst.source = get_node_source(src)
dst.line = get_node_line(src)


NON_SMARTQUOTABLE_PARENT_NODES = (
Expand Down

0 comments on commit 31162a9

Please sign in to comment.