silverstripe/sapphire — pull request #1292 by tractorcow (2013-03-15 01:07:24+00:00)
Title: BUG Issue with ValidationException having blank ValidationResult

This pull request fixes some issues with the behaviour of ValidationException.

Code such as https://github.com/silverstripe/sapphire/blob/3.1/forms/gridfield/GridFieldDetailForm.php#L520 expects that any caught ValidationException has a contained ValidationResult object. Across the code base there seem to be a few inconsistent ways in which this object is created:

* Sometimes with a single ValidationError parameter
* Sometimes with only a message (and maybe an error code)
* Sometimes both of the above

I've attempted to fill in the missing PHPDoc of ValidationException to identify that each of these is correct, and updated the code to more robustly handle each of these situations.

As an effect of this, ValidationException will always have a contained ValidationError object, meaning that user (or other core) code that relies on this behaviour will no longer get null exceptions when calling $e->getResult()->message().

This was tracked down from a CMS bug where an error in DataObject was thrown from https://github.com/silverstripe/sapphire/blob/3.1/model/DataObject.php#L1064 but not being handled correctly.

Thorough test cases included.