Skip to content

Commit

Permalink
Fixed nesting when ExceptionRenderer throws exception
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsteinsland committed Jan 15, 2015
1 parent d39c744 commit f621bb7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/Cake/Error/ErrorHandler.php
Expand Up @@ -125,6 +125,8 @@ public static function handleException(Exception $exception) {
$e->getMessage(),
$e->getTraceAsString()
);

Configure::write('Exception.bail', true);
trigger_error($message, E_USER_ERROR);
}
}
Expand Down Expand Up @@ -249,10 +251,17 @@ public static function handleFatalError($code, $description, $file, $line) {
}

if (Configure::read('debug')) {
call_user_func($exceptionHandler, new FatalErrorException($description, 500, $file, $line));
$exception = new FatalErrorException($description, 500, $file, $line);
} else {
call_user_func($exceptionHandler, new InternalErrorException());
$exception = new InternalErrorException();
}

if (Configure::read('Exception.bail')) {
throw $exception;
}

call_user_func($exceptionHandler, $exception);

return false;
}

Expand Down
34 changes: 34 additions & 0 deletions lib/Cake/Test/Case/Error/ErrorHandlerTest.php
Expand Up @@ -20,6 +20,16 @@
App::uses('Controller', 'Controller');
App::uses('Router', 'Routing');

/**
* A faulty ExceptionRenderer to test nesting.
*/
class FaultyExceptionRenderer extends ExceptionRenderer {

public function render() {
throw new Exception('Error from renderer.');
}
}

/**
* ErrorHandlerTest class
*
Expand Down Expand Up @@ -320,4 +330,28 @@ public function testHandleFatalErrorLog() {
$this->assertContains('[FatalErrorException] Something wrong', $log[1], 'message missing.');
}

/**
* testExceptionRendererNestingDebug method
*
* @expectedException FatalErrorException
* @return void
*/
public function testExceptionRendererNestingDebug() {
Configure::write('debug', 2);
Configure::write('Exception.renderer', 'FaultyExceptionRenderer');
ErrorHandler::handleFatalError(E_USER_ERROR, 'Initial error', __FILE__ ,__LINE__);
}

/**
* testExceptionRendererNestingProduction method
*
* @expectedException InternalErrorException
* @return void
*/
public function testExceptionRendererNestingProduction() {
Configure::write('debug', 0);
Configure::write('Exception.renderer', 'FaultyExceptionRenderer');
ErrorHandler::handleFatalError(E_USER_ERROR, 'Initial error', __FILE__ ,__LINE__);
}

}

0 comments on commit f621bb7

Please sign in to comment.