diff --git a/lib/internal/Magento/Framework/View/Layout.php b/lib/internal/Magento/Framework/View/Layout.php index ebefc6200cdfa..ce8b086dc7b84 100644 --- a/lib/internal/Magento/Framework/View/Layout.php +++ b/lib/internal/Magento/Framework/View/Layout.php @@ -547,8 +547,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; } 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'); + } }