Skip to content

Commit 7209d5c

Browse files
authored
Merge pull request silverstripe#232 from bigfork/silent-exceptions
Fix issue where exceptions triggered by extensions could be silently swallowed
2 parents a44ee69 + b404837 commit 7209d5c

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/Helper/ErrorHandling.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static function safeExtend(
5151
try {
5252
$retVal = $object->extend($method, $a1, $a2, $a3, $a4, $a5, $a6, $a7);
5353
} catch (\Exception $ex) {
54-
if ($logger = Logging::getLogger()) {
54+
if ($logger = Logging::getExceptionLogger()) {
5555
$logger->warning(
5656
'An error occurred when trying to run extension point: '. $object->class . '->' . $method,
5757
[
@@ -89,7 +89,7 @@ public static function safeguard(\Closure $method, $errorMessage)
8989
restore_error_handler();
9090
return $retVal;
9191
} catch (\Exception $ex) {
92-
if ($logger = Logging::getLogger()) {
92+
if ($logger = Logging::getExceptionLogger()) {
9393
$logger->warning($errorMessage, [
9494
'exception' => $ex
9595
]);

src/Helper/Logging.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ public static function getLogger()
4949
return $logger;
5050
}
5151

52+
/**
53+
* @return \Psr\Log\LoggerInterface
54+
*/
55+
public static function getExceptionLogger()
56+
{
57+
$logger = null;
58+
try {
59+
$logger = Injector::inst()->get('SilverStripe\Omnipay\ExceptionLogger');
60+
} catch (NotFoundExceptionInterface $e) {
61+
/* no op */
62+
}
63+
return $logger;
64+
}
65+
5266
/**
5367
* Prepare data for logging by cleaning up the data or simplify it.
5468
* @param mixed $data the incoming data to log

0 commit comments

Comments
 (0)