Skip to content

Commit

Permalink
ENGCOM-7994: improve exception handling in Layout render #27478
Browse files Browse the repository at this point in the history
 - Merge Pull Request #27478 from fsw/magento2:2.4-develop
 - Merged commits:
   1. 9565c44
   2. ab74f29
   3. c30dd60
  • Loading branch information
magento-engcom-team committed Aug 18, 2020
2 parents 4930963 + c30dd60 commit 441b0af
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/internal/Magento/Framework/View/Layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
24 changes: 24 additions & 0 deletions lib/internal/Magento/Framework/View/Test/Unit/LayoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
}
}

0 comments on commit 441b0af

Please sign in to comment.