Skip to content
Snippets Groups Projects

Add component ID to error message

Closed Nikita Malyshev requested to merge issue/drupal-3462700:3462700-add-component-id into 11.x
Files
2
@@ -138,7 +138,7 @@ public function validateDefinition(array $definition, bool $enforce_schemas): bo
...$message_parts,
...$missing_class_errors,
];
$message = implode("/n", $message_parts);
$message = implode("\n", $message_parts);
// Throw the exception with the error message.
throw new InvalidComponentException($message);
}
@@ -208,7 +208,7 @@ function (array $error) use ($context): bool {
return TRUE;
}
$message_parts = array_map(
static function (array $error): string {
static function (array $error) use ($component_id, $context): string {
// We check the error message instead of values and definitions here
// because it's hard to access both given the possible complexity of a
// schema. Since this is a small non critical DX improvement error
@@ -217,11 +217,17 @@ static function (array $error): string {
$error['message'] .= '. This may be because the property is empty instead of having data present. If possible fix the source data, use the |default() twig filter, or update the schema to allow multiple types.';
}
return sprintf("[%s] %s", $error['property'], $error['message']);
// If the property value has been set, print it out for easier
// debugging.
if (isset($context[$error['property']]) && \is_scalar($context[$error['property']])) {
$error['message'] .= \sprintf('. The provided value is: "%s"', $context[$error['property']]);
}
return sprintf('[%s/%s] %s.', $component_id, $error['property'], $error['message']);
},
$errors
);
$message = implode("/n", $message_parts);
$message = implode("\n", $message_parts);
throw new InvalidComponentException($message);
}
@@ -276,7 +282,7 @@ private function validateClassProps(array $props_schema, array $props_raw, strin
}
$props_schema = $this->nullifyClassPropsSchema($props_schema, $classes_per_prop);
if (!empty($error_messages)) {
$message = implode("/n", $error_messages);
$message = implode("\n", $error_messages);
throw new InvalidComponentException($message);
}
return [$props_schema, $props_raw];
Loading