Skip to content

Commit

Permalink
fix: Properly raise on errors (respect strict mode)
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Apr 23, 2020
1 parent 613350a commit 2097208
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/mkdocstrings/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def run(self, parent: Element, blocks: Element) -> None:
data: Any = handler.collector.collect(identifier, selection)
except CollectionError:
log.error(f"mkdocstrings.extension: Could not collect '{identifier}'")
return
raise

log.debug("mkdocstrings.extension: Updating renderer's env")
handler.renderer.update_env(self.md, self._config)
Expand All @@ -161,7 +161,7 @@ def run(self, parent: Element, blocks: Element) -> None:
f"mkdocstrings.extension: Template '{error.name}' not found "
f"for '{handler_name}' handler and theme '{theme_name}'."
)
return
raise

log.debug("mkdocstrings.extension: Loading HTML back into XML tree")
try:
Expand All @@ -182,7 +182,7 @@ def run(self, parent: Element, blocks: Element) -> None:
f"or replace them with < and >"
)
log.error(message)
return
raise

as_xml = atomic_brute_cast(as_xml) # type: ignore
parent.append(as_xml)
Expand Down
13 changes: 4 additions & 9 deletions src/mkdocstrings/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def on_config(self, config: Config, **kwargs) -> Config:
"""
if not config["site_url"]:
log.error("mkdocstrings.plugin: configuration item 'site_url' is required for cross-references")
raise ValueError("site_url is required")

log.debug("mkdocstrings.plugin: Adding extension to the list")

Expand All @@ -165,15 +166,9 @@ def on_page_content(self, html: str, page: Page, config: Config, files: Files, *
`[identifier][]`.
"""
log.debug(f"mkdocstrings.plugin: Mapping identifiers to URLs for page {page.file.src_path}")
try:
for item in page.toc.items:
self.map_urls(page.canonical_url, item)
return html
except TypeError:
# page.canonical_url is None, fail silently.
# An error already has been logged in the on_config hook,
# and warnings will be logged later, in the on_post_page hook.
pass
for item in page.toc.items:
self.map_urls(page.canonical_url, item)
return html

def map_urls(self, base_url: str, anchor: AnchorLink) -> None:
"""
Expand Down

0 comments on commit 2097208

Please sign in to comment.