TypeError from Html::escape() when rendering import errors

Created on 4 October 2025, 7 days ago

Problem/Motivation

In some circumstances, the entityValidate method of EntityProcessorBase causes an exception to be thrown when trying to render error messages.

TypeError: Drupal\Component\Utility\Html::escape(): Argument #1 ($text) must be of type string, null given, called in /var/www/html/public_html/core/lib/Drupal/Component/Render/FormattableMarkup.php on line 238 in Drupal\Component\Utility\Html::escape() (line 433 of /var/www/html/public_html/core/lib/Drupal/Component/Utility/Html.php).

This is coming from $this->renderer->renderRoot($element), when trying to run an import with the attached feed config.

Stepping through in xdebug, I could see that the value of $element was:

array (
  #theme => 'item_list',
  #items => 
  array (
    0 => 
    Drupal\Component\Render\FormattableMarkup::__set_state(array(
      string => '@property_name: @error',
      arguments => 
      array (
        @property_name => 'field_address.0.administrative_area',
        @error => 
        Drupal\Core\StringTranslation\TranslatableMarkup::__set_state(array(
          string => '@name field must be blank.',
          arguments => 
          array (
            @name => null,
          ),
          translatedMarkup => null,
          options => 
          array (
            langcode => null,
          ),
          stringTranslation => null,
        )),
      ),
    )),
    1 => 
    Drupal\Component\Render\FormattableMarkup::__set_state(array(
      string => '@property_name: @error',
      arguments => 
      array (
        @property_name => 'field_address.0.dependent_locality',
        @error => 
        Drupal\Core\StringTranslation\TranslatableMarkup::__set_state(array(
          string => '@name field must be blank.',
          arguments => 
          array (
            @name => null,
          ),
          translatedMarkup => null,
          options => 
          array (
            langcode => null,
          ),
          stringTranslation => null,
        )),
      ),
    )),
  ),
)

Steps to reproduce

Proposed resolution

Ensure that the exception is not thrown so that the error message can be displayed.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇬🇧United Kingdom malcomio

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

Merge Requests

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