From 9565c44b1ca474825731b4ed265724238540f6ad Mon Sep 17 00:00:00 2001 From: Franciszek Wawrzak Date: Fri, 27 Mar 2020 23:55:28 +0100 Subject: [PATCH 1/2] improve exception handling in Layout render --- lib/internal/Magento/Framework/View/Layout.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/View/Layout.php b/lib/internal/Magento/Framework/View/Layout.php index a622006f32a1e..02dbd5e005535 100644 --- a/lib/internal/Magento/Framework/View/Layout.php +++ b/lib/internal/Magento/Framework/View/Layout.php @@ -545,8 +545,7 @@ public function renderNonCachedElement($name) if ($this->appState->getMode() === AppState::MODE_DEVELOPER) { throw $e; } - $message = ($e instanceof LocalizedException) ? $e->getLogMessage() : $e->getMessage(); - $this->logger->critical($message); + $this->logger->critical($e); } return $result; } From c30dd6029f88beada07e2a1f95ff74904eb8365b Mon Sep 17 00:00:00 2001 From: "vadim.malesh" Date: Mon, 10 Aug 2020 10:11:43 +0300 Subject: [PATCH 2/2] add unit test --- .../Framework/View/Test/Unit/LayoutTest.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/internal/Magento/Framework/View/Test/Unit/LayoutTest.php b/lib/internal/Magento/Framework/View/Test/Unit/LayoutTest.php index 23f35dfab7cc8..31606b55f6519 100644 --- a/lib/internal/Magento/Framework/View/Test/Unit/LayoutTest.php +++ b/lib/internal/Magento/Framework/View/Test/Unit/LayoutTest.php @@ -19,6 +19,7 @@ use Magento\Framework\View\Element\AbstractBlock; use Magento\Framework\View\Element\Template; use Magento\Framework\View\Layout; +use Magento\Framework\View\Layout\BuilderInterface; use Magento\Framework\View\Layout\Data\Structure as LayoutStructure; use Magento\Framework\View\Layout\Element; use Magento\Framework\View\Layout\Generator\Block; @@ -1169,4 +1170,27 @@ public function renderElementDisplayDataProvider(): array [null], ]; } + + /** + * Test render element with exception + * + * @return void + */ + public function testRenderNonCachedElementWithException(): void + { + $exception = new \Exception('Error message'); + + $builderMock = $this->createMock(BuilderInterface::class); + $builderMock->expects($this->once()) + ->method('build') + ->willThrowException($exception); + + $this->loggerMock->expects($this->once()) + ->method('critical') + ->with($exception); + + $model = clone $this->model; + $model->setBuilder($builderMock); + $model->renderNonCachedElement('test_container'); + } }