/waste-collection-schedule crashes if a plugin has not been set yet

Created on 3 June 2025, 9 days ago

Problem/Motivation

I was a little over-eager and went to /waste-collection-schedule without having first set up the module.

The page crashes with:

Drupal\Component\Plugin\Exception\PluginNotFoundException: The "" plugin does not exist. Valid plugin IDs for Plugin/DataProvider are: csv_data_provider, example_data_provider in Drupal\Core\Plugin\DefaultPluginManager->doGetDefinition() (line 53 of core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php).

Drupal\Core\Plugin\DefaultPluginManager->getDefinition() (Line: 16)
Drupal\Core\Plugin\Factory\ContainerFactory->createInstance() (Line: 83)
Drupal\Component\Plugin\PluginManagerBase->createInstance() (Line: 90)
Drupal\localgov_waste_collection\Controller\WasteCollectionController->__construct() (Line: 97)

This is also a situation that could occur if a developer uninstalls the module which provides the plugin which is set. Or if a module update moves the plugin or breaks it.

Steps to reproduce

Proposed resolution

The controller should recover cleanly from this and show a normal page with an error message -- a badly configured site should never cause an exception.

But it's not really possible to recover from this exception in the controller class's constructor -- we're not in a place where we can return something yet.

I would move these lines:

    $plugin_id = $this->config->get('active_data_provider');
    $this->dataProvider = $this->dataProviderManager->createInstance($plugin_id);

to a helper method like getDataProvider(), and have the various content callbacks call that when they need the plugin, with a try/catch around it.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇬🇧United Kingdom joachim

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024