From b1d3bc9b4df7311b54ae420fab7b461e472a8a8e Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Thu, 10 Jan 2019 12:10:53 +0100 Subject: [PATCH] Sync, IcingaObjectGroups: avoid generic Exceptions --- library/Director/Import/Sync.php | 19 +++++++++---------- .../Director/Objects/IcingaObjectGroups.php | 16 ++++++++++++++-- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/library/Director/Import/Sync.php b/library/Director/Import/Sync.php index 2629f98f..a3d9d386 100644 --- a/library/Director/Import/Sync.php +++ b/library/Director/Import/Sync.php @@ -98,7 +98,8 @@ class Sync * Retrieve modifications a given SyncRule would apply * * @return array Array of IcingaObject elements - * @throws Exception + * @throws \Icinga\Exception\NotFoundError + * @throws \Icinga\Module\Director\Exception\DuplicateKeyException */ public function getExpectedModifications() { @@ -202,7 +203,6 @@ class Sync * Instantiates all related ImportSource objects * * @return self - * @throws IcingaException * @throws \Icinga\Exception\NotFoundError */ protected function prepareRelatedImportSources() @@ -249,7 +249,7 @@ class Sync /** * Fetch latest imported data rows from all involved import sources * @return Sync - * @throws IcingaException + * @throws \Icinga\Exception\NotFoundError */ protected function fetchImportedData() { @@ -433,9 +433,8 @@ class Sync /** * @return array - * @throws IcingaException * @throws \Icinga\Exception\NotFoundError - * @throws \Icinga\Exception\ProgrammingError + * @throws \Icinga\Module\Director\Exception\DuplicateKeyException */ protected function prepareNewObjects() { @@ -476,9 +475,8 @@ class Sync * @param $row * @param DbObject $object * @param $sourceId - * @throws IcingaException * @throws \Icinga\Exception\NotFoundError - * @throws \Icinga\Exception\ProgrammingError + * @throws \Icinga\Module\Director\Exception\DuplicateKeyException */ protected function prepareNewObject($row, DbObject $object, $sourceId) { @@ -598,7 +596,8 @@ class Sync * TODO: Split this into smaller methods * * @return DbObject|IcingaObject[] List of modified IcingaObjects - * @throws Exception + * @throws \Icinga\Exception\NotFoundError + * @throws \Icinga\Module\Director\Exception\DuplicateKeyException */ protected function prepare() { @@ -663,7 +662,7 @@ class Sync /** * @param $key * @param DbObject|IcingaObject $object - * @throws IcingaException + * @throws \Icinga\Exception\NotFoundError */ protected function processObject($key, $object) { @@ -677,7 +676,7 @@ class Sync /** * @param $key * @param DbObject|IcingaObject $object - * @throws IcingaException + * @throws \Icinga\Exception\NotFoundError */ protected function refreshObject($key, $object) { diff --git a/library/Director/Objects/IcingaObjectGroups.php b/library/Director/Objects/IcingaObjectGroups.php index 56d02280..8a8510d4 100644 --- a/library/Director/Objects/IcingaObjectGroups.php +++ b/library/Director/Objects/IcingaObjectGroups.php @@ -5,12 +5,12 @@ namespace Icinga\Module\Director\Objects; use Countable; use Exception; use Icinga\Exception\NotFoundError; -use Icinga\Exception\ProgrammingError; use Icinga\Module\Director\Db\Cache\PrefetchCache; use Icinga\Module\Director\IcingaConfig\IcingaConfigRenderer; use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c; use Icinga\Module\Director\IcingaConfig\IcingaLegacyConfigHelper as c1; use Iterator; +use RuntimeException; class IcingaObjectGroups implements Iterator, Countable, IcingaConfigRenderer { @@ -85,6 +85,11 @@ class IcingaObjectGroups implements Iterator, Countable, IcingaConfigRenderer return null; } + /** + * @param $group + * @return $this + * @throws NotFoundError + */ public function set($group) { if (! is_array($group)) { @@ -155,6 +160,13 @@ class IcingaObjectGroups implements Iterator, Countable, IcingaConfigRenderer $this->idx = array_keys($this->groups); } + /** + * @param $group + * @param string $onError + * @return $this + * @throws NotFoundError + * @throws \Icinga\Module\Director\Exception\DuplicateKeyException + */ public function add($group, $onError = 'fail') { // TODO: only one query when adding array @@ -204,7 +216,7 @@ class IcingaObjectGroups implements Iterator, Countable, IcingaConfigRenderer } } } else { - throw new ProgrammingError( + throw new RuntimeException( 'Invalid group object: %s', var_export($group, 1) );