Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Unified error handlers. Now the regular error handler will receive th…

…e fatal errors too.
  • Loading branch information...
commit 9beaa9602f959b41fedc417de492514243809a7a 1 parent a72288c
@jrbasso jrbasso authored
View
3  app/Config/core.php
@@ -41,8 +41,6 @@
*
* Options:
*
- * - `fatalErrorHandler` - callback - The callback to handle fatal errors. You can set this to any
- * callable type, including anonymous functions. Setting it to false will disable the feature.
* - `handler` - callback - The callback to handle errors. You can set this to any callable type,
* including anonymous functions.
* - `level` - int - The level of errors you are interested in capturing.
@@ -51,7 +49,6 @@
* @see ErrorHandler for more information on error handling and configuration.
*/
Configure::write('Error', array(
- 'fatalErrorHandler' => 'ErrorHandler::handleFatalError',
'handler' => 'ErrorHandler::handleError',
'level' => E_ALL & ~E_DEPRECATED,
'trace' => true
View
3  lib/Cake/Console/Templates/skel/Config/core.php
@@ -41,8 +41,6 @@
*
* Options:
*
- * - `fatalErrorHandler` - callback - The callback to handle fatal errors. You can set this to any
- * callable type, including anonymous functions. Setting it to false will disable the feature.
* - `handler` - callback - The callback to handle errors. You can set this to any callable type,
* including anonymous functions.
* - `level` - int - The level of errors you are interested in capturing.
@@ -51,7 +49,6 @@
* @see ErrorHandler for more information on error handling and configuration.
*/
Configure::write('Error', array(
- 'fatalErrorHandler' => 'ErrorHandler::handleFatalError',
'handler' => 'ErrorHandler::handleError',
'level' => E_ALL & ~E_DEPRECATED,
'trace' => true
View
9 lib/Cake/Core/App.php
@@ -913,14 +913,11 @@ protected static function _checkFatalError() {
return;
}
- $fatalErrorHandler = Configure::read('Error.fatalErrorHandler');
- if ($fatalErrorHandler === null) {
- $fatalErrorHandler = 'ErrorHandler::handleFatalError';
- }
- if (!is_callable($fatalErrorHandler)) {
+ $errorHandler = Configure::read('Error.handler');
+ if (!is_callable($errorHandler)) {
return;
}
- call_user_func($fatalErrorHandler, $lastError);
+ call_user_func($errorHandler, $lastError['type'], $lastError['message'], $lastError['file'], $lastError['line'], array());
}
}
View
19 lib/Cake/Error/ErrorHandler.php
@@ -158,6 +158,9 @@ public static function handleError($code, $description, $file = null, $line = nu
}
$errorConfig = Configure::read('Error');
list($error, $log) = self::mapErrorCode($code);
+ if ($log === LOG_ERROR) {
+ return self::handleFatalError($code, $description, $file, $line);
+ }
$debug = Configure::read('debug');
if ($debug) {
@@ -186,24 +189,28 @@ public static function handleError($code, $description, $file = null, $line = nu
/**
* Generate an error page when some fatal error happens.
*
- * @param array $error Array with error information. See `error_get_last()` function
- * @return void
+ * @param integer $code Code of error
+ * @param string $description Error description
+ * @param string $file File on which error occurred
+ * @param integer $line Line that triggered the error
+ * @return boolean
*/
- public static function handleFatalError($error) {
- $logMessage = 'Fatal Error (' . $error['type'] . '): ' . $error['message'] . ' in [' . $error['file'] . ', line ' . $error['line'] . ']';
+ public static function handleFatalError($code, $description, $file, $line) {
+ $logMessage = 'Fatal Error (' . $code . '): ' . $description . ' in [' . $file . ', line ' . $line . ']';
CakeLog::write(LOG_ERROR, $logMessage);
$exceptionHandler = Configure::read('Exception.handler');
if (!is_callable($exceptionHandler)) {
- return;
+ return false;
}
ob_clean();
if (Configure::read('debug')) {
- call_user_func($exceptionHandler, new FatalErrorException($error['message'], 500, $error['file'], $error['line']));
+ call_user_func($exceptionHandler, new FatalErrorException($description, 500, $file, $line));
} else {
call_user_func($exceptionHandler, new InternalErrorException());
}
+ return false;
}
/**
View
9 lib/Cake/Test/Case/Error/ErrorHandlerTest.php
@@ -89,7 +89,6 @@ public static function errorProvider() {
return array(
array(E_USER_NOTICE, 'Notice'),
array(E_USER_WARNING, 'Warning'),
- array(E_USER_ERROR, 'Fatal Error'),
);
}
@@ -248,11 +247,10 @@ public function testHandleFatalErrorPage() {
$originalDebugLevel = Configure::read('debug');
$line = __LINE__;
- $error = array('type' => E_ERROR, 'message' => 'Something wrong', 'file' => __FILE__, 'line' => $line);
ob_start();
Configure::write('debug', 1);
- ErrorHandler::handleFatalError($error);
+ ErrorHandler::handleFatalError(E_ERROR, 'Something wrong', __FILE__, $line);
$result = ob_get_clean();
$this->assertContains('Something wrong', $result, 'message missing.');
$this->assertContains(__FILE__, $result, 'filename missing.');
@@ -260,7 +258,7 @@ public function testHandleFatalErrorPage() {
ob_start();
Configure::write('debug', 0);
- ErrorHandler::handleFatalError($error);
+ ErrorHandler::handleFatalError(E_ERROR, 'Something wrong', __FILE__, $line);
$result = ob_get_clean();
$this->assertNotContains('Something wrong', $result, 'message must not appear.');
$this->assertNotContains(__FILE__, $result, 'filename must not appear.');
@@ -280,10 +278,9 @@ public function testHandleFatalErrorLog() {
if (file_exists(LOGS . 'error.log')) {
unlink(LOGS . 'error.log');
}
- $error = array('type' => E_ERROR, 'message' => 'Something wrong', 'file' => __FILE__, 'line' => __LINE__);
ob_start();
- ErrorHandler::handleFatalError($error);
+ ErrorHandler::handleFatalError(E_ERROR, 'Something wrong', __FILE__, __LINE__);
ob_clean();
$log = file(LOGS . 'error.log');
Please sign in to comment.
Something went wrong with that request. Please try again.