FieldValidationException is thrown when https://api.drupal.org/api/drupal/modules!field!field.attach.inc/functio... is called to validate field data prior to saving an entity via the API.

Callers are expected to catch the exception and provide output that is meaningful to their circumstances.

The problem is that the exception is not very useful. Its message is simply 'Field validation errors', which tells you nothing. The exception has an $errors array, which has the full details of field, language, delta, and the nature of the error, but that's a deeply nested array.

It seems pretty poor DX to require users of this to iterate into this array to get a message out. Eg, I've encountered this in both Services and Migrate, and rather than implement identical code in both, the sensible thing to me seems to improve the exception message.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joachim’s picture

Status: Active » Needs review
FileSize
872 bytes

Not brilliant, as the message inside the array has placeholders and I am not sure how best to handle the t().

stefan.r’s picture

This patch looks good to me. The message inside error_messages is already wrapped in t()'s so I don't see how it's "not brilliant" :)

qjensen’s picture

This patch works well for me. It certainly makes troubleshooting significantly easier. What needs to happen for this patch to be committed?