Skip to content

Commit

Permalink
Prevent a stacktrace for theme: foo when theme is not installed (mk…
Browse files Browse the repository at this point in the history
…docs#3351)

This happens because the `theme` option fails validation (being not installed) but then validation of `plugins` option fatally fails because that option is invalid. Maybe in the future it would be better to change validation so it stops after the first error, because there can be countless such combinations of interactions.
  • Loading branch information
oprypin authored Aug 26, 2023
1 parent 9cc8f24 commit 94e9f17
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 3 additions & 1 deletion mkdocs/config/config_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,9 @@ def load_plugin_with_namespace(self, name: str, config) -> tuple[str, plugins.Ba
else:
# Attempt to load with prepended namespace for the current theme.
if self.theme_key and self._config:
current_theme = self._config[self.theme_key]['name']
current_theme = self._config[self.theme_key]
if not isinstance(current_theme, str):
current_theme = current_theme['name']
if current_theme:
expanded_name = f'{current_theme}/{name}'
if expanded_name in self.installed_plugins:
Expand Down
7 changes: 4 additions & 3 deletions mkdocs/tests/config/config_options_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1137,14 +1137,15 @@ class Schema(Config):

def test_uninstalled_theme_as_string(self) -> None:
class Schema(Config):
option = c.Theme()
theme = c.Theme()
plugins = c.Plugins(theme_key='theme')

with self.expect_error(
option=re.compile(
theme=re.compile(
r"Unrecognised theme name: 'mkdocs2'. The available installed themes are: .+"
)
):
self.get_config(Schema, {'option': "mkdocs2"})
self.get_config(Schema, {'theme': "mkdocs2", 'plugins': "search"})

def test_theme_default(self) -> None:
class Schema(Config):
Expand Down

0 comments on commit 94e9f17

Please sign in to comment.