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.