-
-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Log server-side validation errors so it is easier to troubleshoot/debug afform issues #25533
Conversation
(Standard links)
|
@@ -204,7 +205,7 @@ private static function getRequiredFieldError(string $apiEntity, string $fieldNa | |||
$fullDefn = FormDataModel::getField($apiEntity, $fieldName, 'create'); | |||
$isRequired = $attributes['defn']['required'] ?? $fullDefn['required'] ?? FALSE; | |||
if ($isRequired) { | |||
$label = $attributes['defn']['label'] ?? $fullDefn['label']; | |||
$label = $attributes['defn']['label'] ?? $fullDefn['label'] ?? $fieldName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sometimes label is not set eg. for a select2 and you get the unhelpful error message " is not a required field". This falls back to fieldName so we can work it out.
@@ -68,6 +68,7 @@ protected function processForm() { | |||
\Civi::dispatcher()->dispatch('civi.afform.validate', $event); | |||
$errors = $event->getErrors(); | |||
if ($errors) { | |||
\Civi::log()->error('Afform Validation errors: ' . print_r($errors, TRUE)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mattwire what about instead \Civi::log()->error('Afform Validation Errors: :errors', [':errors' => $errors])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually - that's not the syntax - see https://docs.civicrm.org/dev/en/latest/framework/logging/ - which is based on psr3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, so not sure what I'm supposed to do here? Are we happy with what I've put in or should I change it?
I wonder if this is a good time to use a different log prefix - ie
The behaviour would be the same by default but sites could configure different behaviour for the log (e.g using the I don't have an opinion on whether extra logging is good - but @colemanw will I think.... |
I've been using this for over a month in production. |
@mattwire can you check the review comment by @seamuslee001 above? |
@eileenmcnaughton I added in the log prefix |
Thanks @mattwire this looks really useful. |
Overview
Validation error not always returned to the form making it difficult to debug. Log it so we can easily debug.
Before
Validation error details not returned to form.
After
Validation error detail logged.
Technical Details
Comments