Skip to content

Commit

Permalink
Merge pull request #232 from bigfork/silent-exceptions
Browse files Browse the repository at this point in the history
Fix issue where exceptions triggered by extensions could be silently swallowed
  • Loading branch information
kinglozzer authored May 11, 2021
2 parents a44ee69 + b404837 commit 7209d5c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Helper/ErrorHandling.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static function safeExtend(
try {
$retVal = $object->extend($method, $a1, $a2, $a3, $a4, $a5, $a6, $a7);
} catch (\Exception $ex) {
if ($logger = Logging::getLogger()) {
if ($logger = Logging::getExceptionLogger()) {
$logger->warning(
'An error occurred when trying to run extension point: '. $object->class . '->' . $method,
[
Expand Down Expand Up @@ -89,7 +89,7 @@ public static function safeguard(\Closure $method, $errorMessage)
restore_error_handler();
return $retVal;
} catch (\Exception $ex) {
if ($logger = Logging::getLogger()) {
if ($logger = Logging::getExceptionLogger()) {
$logger->warning($errorMessage, [
'exception' => $ex
]);
Expand Down
14 changes: 14 additions & 0 deletions src/Helper/Logging.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ public static function getLogger()
return $logger;
}

/**
* @return \Psr\Log\LoggerInterface
*/
public static function getExceptionLogger()
{
$logger = null;
try {
$logger = Injector::inst()->get('SilverStripe\Omnipay\ExceptionLogger');
} catch (NotFoundExceptionInterface $e) {
/* no op */
}
return $logger;
}

/**
* Prepare data for logging by cleaning up the data or simplify it.
* @param mixed $data the incoming data to log
Expand Down

0 comments on commit 7209d5c

Please sign in to comment.