Skip to content

Commit 2e85464

Browse files
committed
Improved error message in group plugin
1 parent 4154a94 commit 2e85464

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

material/plugins/group/plugin.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from collections.abc import Callable
2424
from mkdocs.config.config_options import Plugins
2525
from mkdocs.config.defaults import MkDocsConfig
26+
from mkdocs.exceptions import PluginError
2627
from mkdocs.plugins import BasePlugin, event_priority
2728

2829
from .config import GroupConfig
@@ -65,8 +66,14 @@ def on_config(self, config):
6566

6667
# Load all plugins in group
6768
self.plugins: dict[str, BasePlugin] = {}
68-
for name, plugin in self._load(option):
69-
self.plugins[name] = plugin
69+
try:
70+
for name, plugin in self._load(option):
71+
self.plugins[name] = plugin
72+
73+
# The plugin could not be loaded, likely because it's not installed or
74+
# misconfigured, so we raise a plugin error for a nicer error message
75+
except Exception as e:
76+
raise PluginError(str(e))
7077

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

100107
# -------------------------------------------------------------------------
101108

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

src/plugins/group/plugin.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from collections.abc import Callable
2424
from mkdocs.config.config_options import Plugins
2525
from mkdocs.config.defaults import MkDocsConfig
26+
from mkdocs.exceptions import PluginError
2627
from mkdocs.plugins import BasePlugin, event_priority
2728

2829
from .config import GroupConfig
@@ -65,8 +66,14 @@ def on_config(self, config):
6566

6667
# Load all plugins in group
6768
self.plugins: dict[str, BasePlugin] = {}
68-
for name, plugin in self._load(option):
69-
self.plugins[name] = plugin
69+
try:
70+
for name, plugin in self._load(option):
71+
self.plugins[name] = plugin
72+
73+
# The plugin could not be loaded, likely because it's not installed or
74+
# misconfigured, so we raise a plugin error for a nicer error message
75+
except Exception as e:
76+
raise PluginError(str(e))
7077

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

100107
# -------------------------------------------------------------------------
101108

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

0 commit comments

Comments
 (0)