Skip to content
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

DOC Show more information in ValidationException message #677

Merged

Conversation

emteknetnz
Copy link
Member

@emteknetnz emteknetnz force-pushed the pulls/6.0/validation-values branch 2 times, most recently from ec16e8b to 7be0d77 Compare January 16, 2025 23:38
@emteknetnz emteknetnz force-pushed the pulls/6.0/validation-values branch 2 times, most recently from 902631b to e6d717a Compare January 30, 2025 03:11
@emteknetnz emteknetnz marked this pull request as ready for review January 31, 2025 04:03
Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably worth adding a note that out of the box the only validation messages which have this additional context are ones produced by a call to DataObject::validate().

Also add some docs around the new API in the validation documentation section.

@emteknetnz
Copy link
Member Author

Also add some docs around the new API in the validation documentation section.

I don't know how to do this. The most relevant section would be here

We could add something like this, but it seems like far too much basically irrelevant detail

DataObject::validate() will also call ValidationResult::setModelClass() and ValidationResult::setRecordID() with static::class and $this->ID respectively, this is done to provide context to the validation result and will be used to update the error messages with the model class and record ID when in a CLI context, or when the current controller is DevelopmentAdmin i.e. the controller used when running dev/build.

@emteknetnz emteknetnz force-pushed the pulls/6.0/validation-values branch from e6d717a to 1973b19 Compare February 4, 2025 22:05
@GuySartorelli
Copy link
Member

GuySartorelli commented Feb 6, 2025

I'm not saying we should document what DataObject does - but we should document that developers can call setModelClass() and setRecordID() on their own validation result instances in order to provide that information which will then be included in the ValidationException.

I wonder if we should also provide setModelClass() and setRecordID() for the exception class itself, so that direct validation exceptions don't have to have a validation result object to benefit from that? But that's just an idle thought that you can feel free to ignore if you wish.

@emteknetnz
Copy link
Member Author

Updated

@emteknetnz emteknetnz force-pushed the pulls/6.0/validation-values branch from 1973b19 to b020233 Compare February 6, 2025 23:28
@emteknetnz emteknetnz force-pushed the pulls/6.0/validation-values branch from b020233 to 955ea81 Compare February 7, 2025 05:27
Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, will merge after code PRs

@GuySartorelli GuySartorelli merged commit 1ac73e3 into silverstripe:6.0 Feb 10, 2025
3 checks passed
@GuySartorelli GuySartorelli deleted the pulls/6.0/validation-values branch February 10, 2025 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants