From 38ad9c46568b6b3dd04d0826ceecc47d143a18f6 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Mon, 24 Jun 2019 15:51:07 +0200 Subject: [PATCH 1/4] Make sure we close all output-buffer we started beforehand --- src/Whoops/Run.php | 52 ++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/src/Whoops/Run.php b/src/Whoops/Run.php index cfaaa5e..b5718b5 100644 --- a/src/Whoops/Run.php +++ b/src/Whoops/Run.php @@ -303,38 +303,40 @@ final class Run implements RunInterface // we might want to send it straight away to the client, // or return it silently. $this->system->startOutputBuffering(); + + try { + // Just in case there are no handlers: + $handlerResponse = null; + $handlerContentType = null; - // Just in case there are no handlers: - $handlerResponse = null; - $handlerContentType = null; + foreach ($this->handlerQueue as $handler) { + $handler->setRun($this); + $handler->setInspector($inspector); + $handler->setException($exception); - foreach ($this->handlerQueue as $handler) { - $handler->setRun($this); - $handler->setInspector($inspector); - $handler->setException($exception); + // The HandlerInterface does not require an Exception passed to handle() + // and neither of our bundled handlers use it. + // However, 3rd party handlers may have already relied on this parameter, + // and removing it would be possibly breaking for users. + $handlerResponse = $handler->handle($exception); - // The HandlerInterface does not require an Exception passed to handle() - // and neither of our bundled handlers use it. - // However, 3rd party handlers may have already relied on this parameter, - // and removing it would be possibly breaking for users. - $handlerResponse = $handler->handle($exception); + // Collect the content type for possible sending in the headers. + $handlerContentType = method_exists($handler, 'contentType') ? $handler->contentType() : null; - // Collect the content type for possible sending in the headers. - $handlerContentType = method_exists($handler, 'contentType') ? $handler->contentType() : null; - - if (in_array($handlerResponse, [Handler::LAST_HANDLER, Handler::QUIT])) { - // The Handler has handled the exception in some way, and - // wishes to quit execution (Handler::QUIT), or skip any - // other handlers (Handler::LAST_HANDLER). If $this->allowQuit - // is false, Handler::QUIT behaves like Handler::LAST_HANDLER - break; + if (in_array($handlerResponse, [Handler::LAST_HANDLER, Handler::QUIT])) { + // The Handler has handled the exception in some way, and + // wishes to quit execution (Handler::QUIT), or skip any + // other handlers (Handler::LAST_HANDLER). If $this->allowQuit + // is false, Handler::QUIT behaves like Handler::LAST_HANDLER + break; + } } + + $willQuit = $handlerResponse == Handler::QUIT && $this->allowQuit(); + } finally { + $output = $this->system->cleanOutputBuffer(); } - $willQuit = $handlerResponse == Handler::QUIT && $this->allowQuit(); - - $output = $this->system->cleanOutputBuffer(); - // If we're allowed to, send output generated by handlers directly // to the output, otherwise, and if the script doesn't quit, return // it so that it may be used by the caller From 3eb5a59ebd3f22a3b637d00a3d28910d3c72231d Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Mon, 24 Jun 2019 16:00:23 +0200 Subject: [PATCH 2/4] tests: Make sure we close all output-buffer we started beforehand --- tests/Whoops/Handler/PlainTextHandlerTest.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/Whoops/Handler/PlainTextHandlerTest.php b/tests/Whoops/Handler/PlainTextHandlerTest.php index 4b92fcc..d4a869a 100644 --- a/tests/Whoops/Handler/PlainTextHandlerTest.php +++ b/tests/Whoops/Handler/PlainTextHandlerTest.php @@ -63,10 +63,13 @@ class PlainTextHandlerTest extends TestCase $run->register(); $exception = $exception ?: $this->getException(); - ob_start(); - $run->handleException($exception); - - return ob_get_clean(); + + try { + ob_start(); + $run->handleException($exception); + } finally { + return ob_get_clean(); + } } /** From 9ea1027d37eb0c25ef9f4e2170325ff48f9421ca Mon Sep 17 00:00:00 2001 From: Jeroen Derks Date: Wed, 26 Jun 2019 07:45:46 +0200 Subject: [PATCH 3/4] updated line numbers in PlainTextHandlerTest to handle added lines --- tests/Whoops/Handler/PlainTextHandlerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Whoops/Handler/PlainTextHandlerTest.php b/tests/Whoops/Handler/PlainTextHandlerTest.php index d4a869a..3432c91 100644 --- a/tests/Whoops/Handler/PlainTextHandlerTest.php +++ b/tests/Whoops/Handler/PlainTextHandlerTest.php @@ -269,11 +269,11 @@ class PlainTextHandlerTest extends TestCase RuntimeException::class, 'Outer exception message', __FILE__, - 258, + 261, "\nCaused by\n" . RuntimeException::class, 'Inner exception message', __FILE__, - 258 + 261 ), $text ); From f9773aa988330b438be548419413b6774279da20 Mon Sep 17 00:00:00 2001 From: Jeroen Derks Date: Tue, 2 Jul 2019 08:31:37 +0200 Subject: [PATCH 4/4] updated function handleException() moved assignments outside of try/catch (#3) --- src/Whoops/Run.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Whoops/Run.php b/src/Whoops/Run.php index b5718b5..77ec212 100644 --- a/src/Whoops/Run.php +++ b/src/Whoops/Run.php @@ -304,11 +304,11 @@ final class Run implements RunInterface // or return it silently. $this->system->startOutputBuffering(); - try { - // Just in case there are no handlers: - $handlerResponse = null; - $handlerContentType = null; + // Just in case there are no handlers: + $handlerResponse = null; + $handlerContentType = null; + try { foreach ($this->handlerQueue as $handler) { $handler->setRun($this); $handler->setInspector($inspector);