From 7d1bf03aedf7b1ac2c7cc412644ba065309ee4ba Mon Sep 17 00:00:00 2001 From: Gerben Oolbekkink Date: Fri, 29 Jan 2021 09:25:08 +0100 Subject: [PATCH] Catch exceptions from render methods --- src/Parser.php | 16 ++++++++++------ src/tag/BbNode.php | 5 +++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Parser.php b/src/Parser.php index 91a3357..93b5218 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -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 .= ''; diff --git a/src/tag/BbNode.php b/src/tag/BbNode.php index cefc598..5142b73 100644 --- a/src/tag/BbNode.php +++ b/src/tag/BbNode.php @@ -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();