Skip to content

Commit

Permalink
Improved error message in group plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
squidfunk committed Sep 11, 2023
1 parent 4154a94 commit 2e85464
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
17 changes: 12 additions & 5 deletions material/plugins/group/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from collections.abc import Callable
from mkdocs.config.config_options import Plugins
from mkdocs.config.defaults import MkDocsConfig
from mkdocs.exceptions import PluginError
from mkdocs.plugins import BasePlugin, event_priority

from .config import GroupConfig
Expand Down Expand Up @@ -65,8 +66,14 @@ def on_config(self, config):

# Load all plugins in group
self.plugins: dict[str, BasePlugin] = {}
for name, plugin in self._load(option):
self.plugins[name] = plugin
try:
for name, plugin in self._load(option):
self.plugins[name] = plugin

# The plugin could not be loaded, likely because it's not installed or
# misconfigured, so we raise a plugin error for a nicer error message
except Exception as e:
raise PluginError(str(e))

# Patch order of plugin methods
for events in option.plugins.events.values():
Expand Down Expand Up @@ -99,9 +106,9 @@ def _load(self, option: Plugins):

# -------------------------------------------------------------------------

# Patch order of plugin events - all other plugin methods are already in the
# right order, so we only need to check those that are part of the group and
# bubble them up into the right location. Some plugin methods may define
# Patch order of plugin methods - all other plugin methods are already in
# the right order, so we only need to check those that are part of the group
# and bubble them up into the right location. Some plugin methods may define
# priorities, so we need to make sure to order correctly within those.
def _patch(self, methods: list[Callable], config: MkDocsConfig):
position = self._get_position(self, config)
Expand Down
17 changes: 12 additions & 5 deletions src/plugins/group/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from collections.abc import Callable
from mkdocs.config.config_options import Plugins
from mkdocs.config.defaults import MkDocsConfig
from mkdocs.exceptions import PluginError
from mkdocs.plugins import BasePlugin, event_priority

from .config import GroupConfig
Expand Down Expand Up @@ -65,8 +66,14 @@ def on_config(self, config):

# Load all plugins in group
self.plugins: dict[str, BasePlugin] = {}
for name, plugin in self._load(option):
self.plugins[name] = plugin
try:
for name, plugin in self._load(option):
self.plugins[name] = plugin

# The plugin could not be loaded, likely because it's not installed or
# misconfigured, so we raise a plugin error for a nicer error message
except Exception as e:
raise PluginError(str(e))

# Patch order of plugin methods
for events in option.plugins.events.values():
Expand Down Expand Up @@ -99,9 +106,9 @@ def _load(self, option: Plugins):

# -------------------------------------------------------------------------

# Patch order of plugin events - all other plugin methods are already in the
# right order, so we only need to check those that are part of the group and
# bubble them up into the right location. Some plugin methods may define
# Patch order of plugin methods - all other plugin methods are already in
# the right order, so we only need to check those that are part of the group
# and bubble them up into the right location. Some plugin methods may define
# priorities, so we need to make sure to order correctly within those.
def _patch(self, methods: list[Callable], config: MkDocsConfig):
position = self._get_position(self, config)
Expand Down

0 comments on commit 2e85464

Please sign in to comment.