From 37ae7e085cf0b9c71c34ba6a622e182c2e482b46 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Sat, 9 Mar 2019 20:23:38 -0500 Subject: [PATCH] Add a hardDeprecationErrors setting (default false) that throws an exception if a deprecation error is logged Signed-off-by: Andrew Welch --- src/config/GeneralConfig.php | 4 ++++ src/errors/DeprecationException.php | 27 +++++++++++++++++++++++++++ src/services/Deprecator.php | 5 +++++ 3 files changed, 36 insertions(+) create mode 100644 src/errors/DeprecationException.php diff --git a/src/config/GeneralConfig.php b/src/config/GeneralConfig.php index 2605011acab..62341c4a23b 100644 --- a/src/config/GeneralConfig.php +++ b/src/config/GeneralConfig.php @@ -352,6 +352,10 @@ class GeneralConfig extends BaseObject * @var bool Whether images transforms should be generated before page load. */ public $generateTransformsBeforePageLoad = false; + /** + * @var bool Whether logged deprecation errors should throw an exception. + */ + public $hardDeprecationErrors = false; /** * @var mixed The image driver Craft should use to cleanse and transform images. By default Craft will auto-detect if ImageMagick is installed and fallback to GD if not. You can explicitly set * either `'imagick'` or `'gd'` here to override that behavior. diff --git a/src/errors/DeprecationException.php b/src/errors/DeprecationException.php new file mode 100644 index 00000000000..aa722285f74 --- /dev/null +++ b/src/errors/DeprecationException.php @@ -0,0 +1,27 @@ + + * @since 3.0 + */ +class DeprecationException extends UserException +{ + /** + * @return string the user-friendly name of this exception + */ + public function getName() + { + return 'Deprecation Error Exception'; + } +} diff --git a/src/services/Deprecator.php b/src/services/Deprecator.php index b07889f2075..2a345e5108b 100644 --- a/src/services/Deprecator.php +++ b/src/services/Deprecator.php @@ -11,6 +11,7 @@ use craft\db\Query; use craft\db\Table; use craft\elements\db\ElementQuery; +use craft\errors\DeprecationException; use craft\helpers\Db; use craft\helpers\Json; use craft\helpers\StringHelper; @@ -127,6 +128,10 @@ public function log(string $key, string $message, string $file = null, int $line } catch (IntegrityException $e) { // todo: remove this try/catch after the next breakpoint } + // Throw an exception if $hardDeprecationErrors is true + if (Craft::$app->getConfig()->getGeneral()->hardDeprecationErrors) { + throw new DeprecationException($message); + } } /**