Improve error-throwing with models that use `$throw = TRUE`
What I did
-
Corrected two behaviours for models that have
$throw = TRUE
set, 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 copyTRUE
from$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_CLASS
afteruse_error_class()
was called on them. This is is because_throw
would get reset toTRUE
for these models, whichcheck_error()
doesn't handle. - Setting to
null
is a better 'total reset', and produces the right outcome._throw
is 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.php
on commit36ae8e62ed053368eabad5e535661b3a32d5b676
of branchfeature/use_error_classes_on_model_results
in the Art Money Website project. - Try and break it!