Skip to content
Permalink
Browse files

Fix PHP7 Throwable to be caught by low level try catch.

  • Loading branch information...
dereuromark committed Nov 25, 2017
1 parent 5a76d37 commit c1f0b94b0b0076fc5b7e206070c6df2c8d08be23
Showing with 27 additions and 10 deletions.
  1. +1 −1 src/Error/Debugger.php
  2. +26 −9 src/Error/ErrorHandler.php
@@ -766,7 +766,7 @@ public static function addFormat($format, array $strings)
/**
* Takes a processed array of data from an error and displays it in the chosen format.
*
* @param string $data Data to output.
* @param array $data Data to output.
* @return void
*/
public function outputError($data)
@@ -18,6 +18,7 @@
use Cake\Core\App;
use Exception;
use Throwable;
/**
* Error Handler provides basic error and exception handling for your application. It captures and
@@ -137,16 +138,10 @@ protected function _displayException($exception)
$response = $renderer->render();
$this->_clearOutput();
$this->_sendResponse($response);
} catch (Throwable $t) {
$this->_logInternalError($t);
} catch (Exception $e) {
// Disable trace for internal errors.
$this->_options['trace'] = false;
$message = sprintf(
"[%s] %s\n%s", // Keeping same message format
get_class($e),
$e->getMessage(),
$e->getTraceAsString()
);
trigger_error($message, E_USER_ERROR);
$this->_logInternalError($e);
}
}
@@ -164,6 +159,28 @@ protected function _clearOutput()
}
}
/**
* Log both PHP5 and PHP7 errors.
*
* The PHP5 part will be removed with 4.0.
*
* @param \Throwable|\Exception $exception
*
* @return void
*/
protected function _logInternalError($exception)
{
// Disable trace for internal errors.
$this->_options['trace'] = false;
$message = sprintf(
"[%s] %s\n%s", // Keeping same message format
get_class($exception),
$exception->getMessage(),
$exception->getTraceAsString()
);
trigger_error($message, E_USER_ERROR);
}
/**
* Method that can be easily stubbed in testing.
*

0 comments on commit c1f0b94

Please sign in to comment.
You can’t perform that action at this time.