Skip to content

Commit

Permalink
Add a hardDeprecationErrors setting (default false) that throws an ex…
Browse files Browse the repository at this point in the history
…ception if a deprecation error is logged

Signed-off-by: Andrew Welch <[email protected]>
  • Loading branch information
khalwat committed Mar 13, 2019
1 parent 93d7bb1 commit 37ae7e0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/config/GeneralConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
27 changes: 27 additions & 0 deletions src/errors/DeprecationException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/

namespace craft\errors;

use yii\base\UserException;

/**
* Class FileException
*
* @author Pixel & Tonic, Inc. <[email protected]>
* @since 3.0
*/
class DeprecationException extends UserException
{
/**
* @return string the user-friendly name of this exception
*/
public function getName()
{
return 'Deprecation Error Exception';
}
}
5 changes: 5 additions & 0 deletions src/services/Deprecator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

/**
Expand Down

0 comments on commit 37ae7e0

Please sign in to comment.