Proposal for a catchable Block Exception when the admin config is bad.

Created on 20 July 2017, about 8 years ago
Updated 8 October 2025, 3 days ago

Problem/Motivation

When coding more complex blocks it is possible, though unlikely for the administrator to mis-configure the block. In the code the programmer can throw an exception, which halts page rendering entirely, or let the page crash when the bad config is tried which is undesirable.

Proposed resolution

Provide an Exception object that can be thrown by the block plugin. The block rendering code will be slightly modified to operate in a try/catch block and this object will get caught if thrown. When caught the block isn't rendered at all, and the rendering of the exception message will follow the mode Drupal is currently operating in. If errors are being displayed the error message will be placed where the block would have been.

Remaining tasks

  1. The unit test is simple enough - a block with a build function that throws this exception every single time.
  2. The exception object itself should also be unremarkable, extending from \Exception but having no unique code of its own.
  3. Where the exception lives and it's naming convention needs some consideration because this is unlikely to be only place in Drupal where a recoverable exception would be useful (recoverable in the sense that pages keep displaying, sans the block that has a config issue.
  4. 4. The trickiest bit of code will be the insertion of the try/catch block in the block render routine.

User interface changes

None.

API changes

This is a new option for module developers. There are no changes to the existing API.

Data model changes

None - but it should be noted that a change in data model between module versions which renders a configuration option invalid is probably the most likely reason for this proposed exception to be thrown.

✨ Feature request
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

plugin system

Created by

πŸ‡ΊπŸ‡ΈUnited States Aki Tendo

Live updates comments and jobs are added and updated live.
  • stale-issue-cleanup

    To track issues in the developing policy for closing stale issues, [Policy, no patch] closing older issues

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.

No activities found.

Production build 0.71.5 2024