Fatal error when assertions are enabled and json-schema library is not available

Created on 24 April 2023, over 1 year ago
Updated 25 April 2023, over 1 year ago

Problem/Motivation

There is an Error that causes a WSOD when using SDC under certain conditions.

Conditions:

  1. Assertions are enabled. This typically happens in local environments via settings.local.php. In particular, it needs assert_options(ASSERT_ACTIVE, TRUE);
  2. The site does not have justinrainbow/json-schema installed. This is typically installed via drupal/core-dev, which is part of drupal/core-recommended

This is an example of the generated trace.

The website encountered an unexpected error. Please try again later.

Error: Typed property Drupal\sdc\Component\ComponentValidator::$validator must not be accessed before initialization in Drupal\sdc\Component\ComponentValidator->validateDefinition() (line 70 of core/modules/sdc/src/Component/ComponentValidator.php).

Drupal\sdc\ComponentPluginManager->isValidDefinition(Array) (Line: 252)
Drupal\sdc\ComponentPluginManager->Drupal\sdc\{closure}(Array) (Line: 56)
Drupal\Component\Assertion\Inspector::assertAll(Object, Array) (Line: 253)
Drupal\sdc\ComponentPluginManager->alterDefinitions(Array) (Line: 295)
Drupal\Core\Plugin\DefaultPluginManager->findDefinitions() (Line: 181)
Drupal\Core\Plugin\DefaultPluginManager->getDefinitions() (Line: 138)
Drupal\sdc\ComponentPluginManager->find('sdc_examples:my-card--light') (Line: 68)
Drupal\sdc\Twig\TwigComponentLoader->exists('sdc_examples:my-card--light') (Line: 88)
Twig\Loader\ChainLoader->getCacheKey('sdc_examples:my-card--light') (Line: 264)
Twig\Environment->getTemplateClass('sdc_examples:my-card--light', NULL) (Line: 205)
Drupal\Core\Template\TwigEnvironment->getTemplateClass('sdc_examples:my-card--light') (Line: 319)
Twig\Template->loadTemplate('sdc_examples:my-card--light', 'core/profiles/demo_umami/themes/umami/templates/components/banner-block/block--bundle--banner-block.html.twig', 38) (Line: 135)

Steps to reproduce

Set up a website that meets the conditions above, and place a component. If you are using Umami, you can paste the following in block--bundle--banner-block.html.twig. You will also need to install and enable sdc_examples β†’ , which provides the components.

Alternatively you can define and place a component of your choosing.

Why did this fell through the cracks?

There are several reasons:

  • The bug is very subtle: !isset($this->validator) (OK) vs !$this->validator (KO). This made it super hard to detect during the many code review rounds.
  • The bug cannot be reproduced using automated tests. That is because automated testing very often uses drupal/core-dev.
  • The bug can only be reproduced when meeting the conditions above

Proposed resolution

Let's fix the bug.

Remaining tasks

  1. .
  2. Review the patch.
  3. Commit the patch.
πŸ› Bug report
Status

Fixed

Version

10.1 ✨

Component
RenderΒ  β†’

Last updated 2 days ago

Created by

e0ipso Can Picafort

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

Comments & Activities

Production build 0.71.5 2024