From 39b984b3f9589159c85e658016ceeddbb1fc54de Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Fri, 19 Aug 2022 10:12:01 +0200 Subject: [PATCH] ObjectInspectionDetail: Handle formatting errors gracefully fixes #621 --- library/Icingadb/Common/ObjectInspectionDetail.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/library/Icingadb/Common/ObjectInspectionDetail.php b/library/Icingadb/Common/ObjectInspectionDetail.php index 0c06fa1a..87c9b526 100644 --- a/library/Icingadb/Common/ObjectInspectionDetail.php +++ b/library/Icingadb/Common/ObjectInspectionDetail.php @@ -7,6 +7,7 @@ namespace Icinga\Module\Icingadb\Common; use DateTime; use DateTimeZone; use Exception; +use Icinga\Exception\IcingaException; use Icinga\Exception\Json\JsonDecodeException; use Icinga\Module\Icingadb\Model\Host; use Icinga\Module\Icingadb\Model\Service; @@ -306,10 +307,16 @@ abstract class ObjectInspectionDetail extends BaseHtmlElement foreach ($data as $name => $value) { if (empty($value) && ($value === null || is_string($value) || is_array($value))) { $value = new EmptyState(t('n. a.')); - } elseif (isset($formatters[$name])) { - $value = call_user_func($formatters[$name], $value); } else { - $value = $this->formatJson($value); + try { + if (isset($formatters[$name])) { + $value = call_user_func($formatters[$name], $value); + } else { + $value = $this->formatJson($value); + } + } catch (Exception $e) { + $value = new EmptyState(IcingaException::describe($e)); + } } $table->addHtml(Table::tr([