Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment | File | Size | Author |
---|---|---|---|
#11 | 3016840-exception-message-11-interdiff.txt | 1.78 KB | tim.plunkett |
#11 | 3016840-exception-message-11.patch | 2.96 KB | tim.plunkett |
#8 | 3016840-exception-message-8-interdiff.txt | 829 bytes | tim.plunkett |
#8 | 3016840-exception-message-8.patch | 2.96 KB | tim.plunkett |
#5 | 3016840-exception-message-5-interdiff.txt | 1.43 KB | tim.plunkett |
Comments
Comment #2
tim.plunkettComment #3
tim.plunkettEven better
Comment #4
EclipseGc CreditAttribution: EclipseGc at Acquia commentedI 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
Comment #5
tim.plunkettLet's assert the actual exception class, not the parent.
Comment #8
tim.plunkettFixed the fail
Comment #9
EclipseGc CreditAttribution: EclipseGc at Acquia commentedWhat an enormous improvement. RTBC
Eclipse
Comment #10
alexpottSo 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?
Comment #11
tim.plunkettThis 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.
Comment #12
EclipseGc CreditAttribution: EclipseGc at Acquia commentedComment #13
alexpottCommitted cee4a5c and pushed to 8.7.x. Thanks!