Skip to content

Commit

Permalink
Catch exceptions from render methods
Browse files Browse the repository at this point in the history
  • Loading branch information
qurben committed Jan 29, 2021
1 parent 19e69d4 commit 7d1bf03
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,16 @@ public function render($blocks, $mode)
if ($block->isAllowed()) {
$block->setContent($this->render($block->getChildren(), $mode));

if ($mode == "light") {
$text .= $block->renderLight();
} elseif ($mode == "plain") {
$text .= $block->renderPlain();
} else {
$text .= $block->render();
try {
if ($mode == "light") {
$text .= $block->renderLight();
} elseif ($mode == "plain") {
$text .= $block->renderPlain();
} else {
$text .= $block->render();
}
} catch (BbException $exception) {
$text .= $exception->getMessage();
}
} else {
$text .= '';
Expand Down
5 changes: 5 additions & 0 deletions src/tag/BbNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,25 @@
namespace CsrDelft\bb\tag;


use CsrDelft\bb\BbException;

interface BbNode
{
/**
* @return string
* @throws BbException
*/
public function renderPlain();

/**
* @return string
* @throws BbException
*/
public function renderLight();

/**
* @return string
* @throws BbException
*/
public function render();

Expand Down

0 comments on commit 7d1bf03

Please sign in to comment.