Skip to content

Improve error-throwing with models that use `$throw = TRUE`

Robert Sinton requested to merge patch/df_model_error_throwing_improvement into master

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 because use_error_class() would copy TRUE from $throw, and then discard it when it was found not to be a string.
    • 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 after use_error_class() was called on them. This is is because _throw would get reset to TRUE for these models, which check_error() doesn't handle.
      • Setting to null is a better 'total reset', and produces the right outcome. _throw is correctly set again the next time check_error() is called.

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 commit 36ae8e62ed053368eabad5e535661b3a32d5b676 of branch feature/use_error_classes_on_model_results in the Art Money Website project.
  • Try and break it!

Merge request reports