Problem/Motivation

\Drupal\Component\Plugin\Discovery\DiscoveryInterface::getDefinition() has a parameter $exception_on_invalid = TRUE. Passing FALSE will return NULL and the calling code can handle the missing plugin themselves. This is common.

In the uncommon case, TRUE is passed an an exception is thrown:

    throw new PluginNotFoundException($plugin_id, sprintf('The "%s" plugin does not exist.', $plugin_id));

I've hit this innumerable times when writing tests, and all I need to know is what actual valid plugin IDs there are.

Proposed resolution

Change the exception to include a list of valid IDs.

Remaining tasks

N/A

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tim.plunkett created an issue. See original summary.

tim.plunkett’s picture

tim.plunkett’s picture

Even better

EclipseGc’s picture

I can't tell you how many times I've had to stick an xdebug stop in the default plugin manager classes just to figure out which plugin manager was actually failing on this. +1000000

Eclipse

tim.plunkett’s picture

Let's assert the actual exception class, not the parent.

Status: Needs review » Needs work

The last submitted patch, 5: 3016840-exception-message-5.patch, failed testing. View results

tim.plunkett’s picture

Status: Needs work » Needs review
FileSize
2.96 KB
829 bytes

Fixed the fail

EclipseGc’s picture

Status: Needs review » Reviewed & tested by the community

What an enormous improvement. RTBC

Eclipse

alexpott’s picture

Status: Reviewed & tested by the community » Needs review

So here's a real message from image cache action plugins
The "image_deprecated_scale" plugin does not exist. Valid plugin IDs for Drupal\image\ImageEffectManager are: "image_convert, image_scale_and_crop, image_scale, image_desaturate, image_resize, image_crop, image_rotate"

I wonder whether to be consistent this should be
The "image_deprecated_scale" plugin does not exist. Valid plugin IDs for Drupal\image\ImageEffectManager are: "image_convert", "image_scale_and_crop", "image_scale", "image_desaturate", "image_resize", "image_crop", "image_rotate"

or leave out the quotes entirely
The "image_deprecated_scale" plugin does not exist. Valid plugin IDs for Drupal\image\ImageEffectManager are: image_convert, image_scale_and_crop, image_scale, image_desaturate, image_resize, image_crop, image_rotate
As the colon does the job of delimiting the list already.

The other thought is sometimes we have a lot of plugins - do we need to be concerned about how big this list can get?

tim.plunkett’s picture

This is an exception message, seeing it should be rare enough, and the length won't really matter. (Especially if the site is configured to show a backtrace!)

I dropped the extraneous quotes.

EclipseGc’s picture

Status: Needs review » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed cee4a5c and pushed to 8.7.x. Thanks!

  • alexpott committed cee4a5c on 8.7.x
    Issue #3016840 by tim.plunkett, EclipseGc, alexpott: When an invalid...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.