Skip to content

Commit 1ac73e3

Browse files
Merge pull request #677 from creative-commoners/pulls/6.0/validation-values
DOC Show more information in ValidationException message
2 parents 772b285 + 955ea81 commit 1ac73e3

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

en/02_Developer_Guides/00_Model/09_Validation.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ sub-classes to specify custom validation, or use the `updateValidate()` extensio
4444

4545
Invalid objects won't be able to be written - a [`ValidationException`](api:SilverStripe\Core\Validation\ValidationException) will be thrown and no write will occur.
4646

47+
If appropriate, you can call [`ValidationResult::setModelClass()`](api:SilverStripe\Core\Validation\ValidationResult::setModelClass())
48+
and [`ValidationResult::setRecordID()`](api:SilverStripe\Core\Validation\ValidationResult::setRecordID()) on your `ValidationResult` instance to set the class and ID of the object being validated. This additional info will show in the validation error messages in a CLI context, as well as in a non-CLI context if the current controller is an instance or a subclass of a controller configured in the [`ValidationException.show_additional_info_non_cli_controllers`](api:SilverStripe\Core\Validation\ValidationException->show_additional_info_non_cli_controllers) configuration.
49+
4750
The return value of `validate()` is a [`ValidationResult`](api:SilverStripe\Core\Validation\ValidationResult) object.
4851

4952
```php

en/08_Changelogs/6.0.0.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ title: 6.0.0 (unreleased)
5050
- [Update JS MIME type, remove `type` in `<script>` tags](#js-mime-type-update)
5151
- [`getSchemaDataDefaults()` now includes attributes](#formfield-schema-data)
5252
- [Remember me token rotation](#remember-me-token-rotation)
53+
- [Validation exceptions shows additional info in some contexts](#validation-exception-info)
5354
- [Full list of removed and changed API (by module, alphabetically)](#api-removed-and-changed)
5455

5556
## Change to commercially supported modules {#changes-to-support}
@@ -1176,6 +1177,14 @@ If you were calling `getSchemaData()` in your `getAttributes()` method in a `For
11761177

11771178
The related `onAfterRenewToken` extension hook has been renamed to `onAfterRenewSession`, and is triggered at the same logical step in the session renewal process.
11781179

1180+
### Validation exceptions shows additional info in some contexts {#validation-exception-info}
1181+
1182+
[`ValidationResult`](api:SilverStripe\Core\Validation\ValidationResult) objects created by [`DataObject::validate()`](api:SilverStripe\ORM\DataObject::validate()) now includes additional information about validation exceptions including the field name that failed validation, and if applicable the model class and record ID. This additional information will be included in the validation message by [`ValidationException`](api:SilverStripe\Core\Validation\ValidationException) if the validation exception happened in a CLI context, or in an HTTP context if the current controller is an instance contained in the [`ValidationException.show_additional_info_non_cli_controllers`](api:SilverStripe\Core\Validation\ValidationException->show_additional_info_non_cli_controllers) configuration or a subclass. By default only [`DevelopmentAdmin`](api:SilverStripe\Dev\DevelopmentAdmin) and subclasses are configured to show additonal information.
1183+
1184+
This is done to help developers debug validation issues that happen outside of a UX context more easily, such as validation exceptions that occur during a `dev/build`.
1185+
1186+
The value of the field that failed validation is intentially not included in the output, as it could contain sensitive information e.g. an API token.
1187+
11791188
### Full list of removed and changed API (by module, alphabetically) {#api-removed-and-changed}
11801189

11811190
<!--- Changes below this line will be automatically regenerated -->

0 commit comments

Comments
 (0)