Skip to content

Commit

Permalink
feat: raise AmbiguousPluginOverrideError for ambibuous plugin overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
nsprenkle committed Aug 16, 2024
1 parent c02cf24 commit db7d24d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion xblock/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def __init__(self, all_entry_points):
super().__init__(msg)


class AmbiguousPluginOverrideError(AmbiguousPluginError):
"""Raised when a class name produces more than one override for an entry_point."""


def _default_select_no_override(identifier, all_entry_points): # pylint: disable=inconsistent-return-statements
"""
Selects plugin for the given identifier, raising on error:
Expand Down Expand Up @@ -72,7 +76,7 @@ def default_select(identifier, all_entry_points):
if len(overrides) == 1:
return overrides[0]
elif len(overrides) > 1:
raise AmbiguousPluginError(all_entry_points)
raise AmbiguousPluginOverrideError(overrides)
return default_plugin


Expand Down
4 changes: 2 additions & 2 deletions xblock/test/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from xblock.core import XBlock
from xblock import plugin
from xblock.plugin import AmbiguousPluginError, PluginMissingError
from xblock.plugin import AmbiguousPluginError, AmbiguousPluginOverrideError, PluginMissingError


class AmbiguousBlock1(XBlock):
Expand Down Expand Up @@ -82,7 +82,7 @@ def test_plugin_override_ambiguous():
"xblock.test.test_plugin.AmbiguousBlock1, "
"xblock.test.test_plugin.AmbiguousBlock2"
)
with pytest.raises(AmbiguousPluginError, match=expected_msg):
with pytest.raises(AmbiguousPluginOverrideError, match=expected_msg):
XBlock.load_class("overridden_block")


Expand Down

0 comments on commit db7d24d

Please sign in to comment.