Fatal error on Agent Add Form: Html::escape() expects string, null given

Created on 9 April 2025, 15 days ago

Problem/Motivation

When accessing the "Agents Add Form" at /admin/structure/ai_agent/add on the Drupal core latest 11.x branch, the site throws a fatal error:

The website encountered an unexpected error. Try again later.

TypeError: Drupal\Component\Utility\Html::escape(): Argument #1 ($text) must be of type string, null given, called in /var/www/html/core/lib/Drupal/Component/Render/FormattableMarkup.php on line 238 in Drupal\Component\Utility\Html::escape() (line 433 of core/lib/Drupal/Component/Utility/Html.php).
Drupal\Component\Render\FormattableMarkup::placeholderEscape() (Line: 187)
Drupal\Component\Render\FormattableMarkup::placeholderFormat() (Line: 195)
Drupal\Core\StringTranslation\TranslatableMarkup->render() (Line: 15)
Drupal\Core\StringTranslation\TranslatableMarkup->__toString()
strip_tags() (Line: 1147)
template_preprocess_html()
call_user_func_array() (Line: 280)
Drupal\Core\Theme\ThemeManager->render() (Line: 453)
Drupal\Core\Render\Renderer->doRender() (Line: 203)
Drupal\Core\Render\Renderer->render() (Line: 162)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 600)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 157)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse() (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray() (Line: 246)
Symfony\Component\EventDispatcher\EventDispatcher::Symfony\Component\EventDispatcher\{closure}() (Line: 206)
Symfony\Component\EventDispatcher\EventDispatcher->callListeners() (Line: 56)
Symfony\Component\EventDispatcher\EventDispatcher->dispatch() (Line: 188)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 53)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 116)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 90)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 53)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 715)
Drupal\Core\DrupalKernel->handle() (Line: 19)

Steps to reproduce

  1. Clone the Drupal core, checkout the latest 11.x branch.
  2. Install the AI Agents module
  3. Navigate to /admin/structure/ai_agent/add
  4. Observe the fatal error on the page

Proposed resolution

TBD

Remaining tasks

  • Identify the root cause
  • Manually verify that the form loads successfully after the fix.

User interface changes

None expected, apart from the form successfully rendering as intended.

API changes

None.

🐛 Bug report
Status

Active

Version

1.1

Component

Code

Created by

🇮🇳India prashant.c Dharamshala

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

Comments & Activities

  • Issue created by @prashant.c
  • 🇮🇳India prashant.c Dharamshala

    It seems to be an error with <?PHP label ?> property being NULL. We can assign an empty string if the value is null.

    ai_agents/src/Form/AiAgentForm.php

    Existing code:

      $form['#title'] = $this->t('AI agent: %label', [
          '%label' => $this->entity->label(),
        ]);
    

    Updated code:

         $form['#title'] = $this->t('AI agent: %label', [
          '%label' => $this->entity->label() ?? $this->t('New AI agent'),
        ]);
    

    This should fix the issue.

  • 🇮🇳India prashant.c Dharamshala

    Seems it got duplicated in favor of https://www.drupal.org/project/ai_agents/issues/3518174 🐛 Unable to create new Agent Active . Closing this one

Production build 0.71.5 2024