Improve error-throwing with models that use `$throw = TRUE`
What I did
-
Corrected two behaviours for models that have
$throw = TRUEset, i.e. they are configured to always use the global default error class.-
Modified
use_error_class()to behave correctly if called on these models.- Prior to this change, models like this would throw exceptions by themselves, but not if
->use_error_class()was called on them. This is becauseuse_error_class()would copyTRUEfrom$throw, and then discard it when it was found not to be a string.
- Prior to this change, models like this would throw exceptions by themselves, but not if
-
Modified
check_error()to improve the way that a model instance's error class is reset at the end of an operation.- Prior to this, models like this would not reset back to using
DF_MODEL_DEFAULT_ERROR_CLASSafteruse_error_class()was called on them. This is is because_throwwould get reset toTRUEfor these models, whichcheck_error()doesn't handle. - Setting to
nullis a better 'total reset', and produces the right outcome._throwis correctly set again the next timecheck_error()is called.
- Prior to this, models like this would not reset back to using
-
Implications
I was preparing to write some docs on the recent changes to DF_Model exception throwing when I came across these edge cases.
Ideally, the test suite should be part of zon core itself, probably using modified blog model classes. One day.
Setup
None
How to test
- Code review
- Review changes to, and run, the test suite
tests/error_class/ModelResultErrorClassTest.phpon commit36ae8e62ed053368eabad5e535661b3a32d5b676of branchfeature/use_error_classes_on_model_resultsin the Art Money Website project. - Try and break it!