From ad5dfc8496a8626f6b3aa1720b4c2e2907e87368 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Tue, 25 Oct 2022 11:10:05 +0200 Subject: [PATCH] BasketSnapshot: simplify error handling We have no IcingaObject here, they're all stdClass instances --- .../DirectorObject/Automation/BasketSnapshot.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/library/Director/DirectorObject/Automation/BasketSnapshot.php b/library/Director/DirectorObject/Automation/BasketSnapshot.php index 96988173..4ddf2cef 100644 --- a/library/Director/DirectorObject/Automation/BasketSnapshot.php +++ b/library/Director/DirectorObject/Automation/BasketSnapshot.php @@ -424,22 +424,18 @@ class BasketSnapshot extends DbObject return JsonString::encode($this->objects, JSON_PRETTY_PRINT); } catch (JsonEncodeException $e) { foreach ($this->objects as $type => $objects) { - foreach ($objects as $key => $object) { + foreach ($objects as $object) { try { JsonString::encode($object); } catch (JsonEncodeException $singleError) { - if ($object instanceof IcingaObject) { - $name = $object->getObjectName(); - } else { - $name = var_export($object, 1); - if (function_exists('iconv')) { - $name = iconv('UTF-8', 'UTF-8//IGNORE', $name); - } + $dump = var_export($object, 1); + if (function_exists('iconv')) { + $dump = iconv('UTF-8', 'UTF-8//IGNORE', $dump); } throw new JsonEncodeException(sprintf( - 'Failed to encode object ot type "%s": "%s", %s', + 'Failed to encode object ot type "%s": %s, %s', $type, - $name, + $dump, $singleError->getMessage() ), $singleError->getCode()); }