The error message showing the field machine name which is not user friendly. In fact, the field label could be in a different language.
Here is an example how to change the error message. (For a node validation).
+$fieldInfo = \Drupal\field\Entity\FieldConfig::loadByName('node', $form['bundle'], $field_name);
+$fieldLabel = $fieldInfo->getLabel();
-$form_state->setErrorByName($field_name, t('The field @field_name has to be unique.', array('@field_name' => $field_name)));
+$form_state->setErrorByName($field_name, t('The field @field_name has to be unique.', array('@field_name' => $fieldLabel)));
Comments
Comment #2
alex_optimComment #3
tucho