Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ private function render($no_output_filter = true, $display = null) {
call_user_func($callback, $this);
}

$renderException = null;
try {

Comment thread
ichaykin marked this conversation as resolved.
// read from cache or render
Expand All @@ -180,9 +181,18 @@ private function render($no_output_filter = true, $display = null) {
$this->getCompiled()->render($this);
}

} catch (\Throwable $e) {
$renderException = $e;
throw $renderException;
} finally {
foreach ($this->endRenderCallbacks as $callback) {
call_user_func($callback, $this);
try {
foreach ($this->endRenderCallbacks as $callback) {
call_user_func($callback, $this);
}
} catch (\Throwable $callbackException) {
if ($renderException === null) {
throw $callbackException;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,31 @@ public function testCapture10()
$this->assertStringContainsString('uppercase', $result);
}

public function testRenderExceptionInsideCaptureIsNotMaskedByEndRenderException()
{
$this->smarty->registerPlugin(\Smarty\Smarty::PLUGIN_FUNCTION, 'capture_fail', function () {
throw new \RuntimeException('render failure inside capture');
});

$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('render failure inside capture');

$this->smarty->fetch('string:{capture}{capture_fail}{/capture}');
}

public function testEndRenderCallbackExceptionIsThrownWhenRenderSucceeds()
{
$template = $this->smarty->createTemplate('string:render succeeds');
$template->endRenderCallbacks[] = function () {
throw new \RuntimeException('end render callback failure');
};

$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('end render callback failure');

$template->fetch();
}

/**
* Test spacings
*
Expand Down