Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 300763

Unhelpful error message with enumeration problem

$
0
0

Problem/Motivation

When a component defines a property with an enum value and is rendered with a value that is not an enum, the error message is unhelpful.

Drupal\Core\Render\Component\Exception\InvalidComponentException: [example] Does not have a value in the enumeration ["foo","bar"] in Drupal\Core\Theme\Component\ComponentValidator->validateProps() (line 223 of core/lib/Drupal/Core/Theme/Component/ComponentValidator.php).

How do you understand what component is causing the problem? There can be multiple components with the same enum values. For example, buttons, inputs, etc., with a variant or color enum property.

This is especially annoying when the enum value is removed from the component after some time and the value for it can be a twig variable and not a direct definition.

Steps to reproduce

$schema: https://git.drupalcode.org/project/drupal/-/raw/HEAD/core/assets/schemas/v1/metadata.schema.json
name: Example
props:
  type: object
  properties:
    example:
      title: Example
      enum:
        - foo
        - bar

{% include 'foo:foo' with { example: 'baz' } only %}

Drupal\Core\Render\Component\Exception\InvalidComponentException: [example] Does not have a value in the enumeration ["foo","bar"] in Drupal\Core\Theme\Component\ComponentValidator->validateProps() (line 223 of core/lib/Drupal/Core/Theme/Component/ComponentValidator.php).

Proposed resolution

Add the component ID to the error message. It will help a lot. At least, you can check all component usage.


Viewing all articles
Browse latest Browse all 300763

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>