Improve exception messages when plugins cannot be found

Created on 20 November 2012, about 12 years ago
Updated 15 September 2023, about 1 year ago

Problem/Motivation

Currently, when a plugin cannot be found, we get this obtuse error message:

Drupal\Component\Plugin\Exception\PluginException: The plugin (%plugin) did not specify an instance class in Drupal\Component\Plugin\Factory\DefaultFactory->getPluginClass() (line 60 of /path/to/webroot/core/lib/Drupal/Component/Plugin/Factory/DefaultFactory.php).

first, this is incorrect - what's usually happening is that no plugin definition was found, not that the found plugin definition did not specify an instance class. second, it gives us very little useful information about WHICH plugin actually failed - we just have the plugin id, not the owner/type information. that's a little tricky to get at.

Proposed resolution

introduce new exceptions - PluginNotFoundException and DerivativeNotFoundException - that can be thrown by the various Discovery implementations when plugins aren't actually found.

Remaining tasks

the exceptions still don't include contextual information about the plugin type when throwing exceptions. we could probably expand the DiscoveryInterface to include such contextual information purely for the purpose of these exceptions.

API changes

any new Discovery classes, decorators, etc., should follow the practice of throwing the appropriate exception for their case.

πŸ“Œ Task
Status

Needs work

Version

11.0 πŸ”₯

Component
PluginΒ  β†’

Last updated 3 days ago

Created by

πŸ‡ΊπŸ‡ΈUnited States sdboyer

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024