diff --git a/doc/82-Changelog.md b/doc/82-Changelog.md index 9653500b..03289063 100644 --- a/doc/82-Changelog.md +++ b/doc/82-Changelog.md @@ -14,6 +14,9 @@ next (will be 1.8.1) ### User Interface * FIX: don't fail when showing a Host overriding multiple inherited groups (#2253) +### Automation, User Interface +* FIX: error message wording on failing related (or parent) object ref (#2224) + 1.8.0 ----- diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php index 6a271607..140e85d0 100644 --- a/library/Director/Objects/IcingaObject.php +++ b/library/Director/Objects/IcingaObject.php @@ -535,7 +535,13 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer $this->connection ); } catch (NotFoundError $e) { - throw new RuntimeException($e->getMessage(), 0, $e); + // Hint: eventually a NotFoundError would be better + throw new RuntimeException(sprintf( + 'Unable to load object referenced from %s "%s", %s', + $this->getShortTableName(), + $this->getObjectName(), + lcfirst($e->getMessage()) + ), $e->getCode(), $e); } $this->reallySet($name, $object->get('id')); diff --git a/library/Director/Objects/IcingaObjectImports.php b/library/Director/Objects/IcingaObjectImports.php index c3835f97..109ec0c8 100644 --- a/library/Director/Objects/IcingaObjectImports.php +++ b/library/Director/Objects/IcingaObjectImports.php @@ -4,6 +4,7 @@ namespace Icinga\Module\Director\Objects; use Countable; use Exception; +use Icinga\Exception\NotFoundError; use Iterator; use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c; use Icinga\Module\Director\IcingaConfig\IcingaConfigRenderer; @@ -251,14 +252,23 @@ class IcingaObjectImports implements Iterator, Countable, IcingaConfigRenderer $connection = $this->object->getConnection(); /** @var IcingaObject $class */ $class = $this->getImportClass(); - if (is_array($this->object->getKeyName())) { - // Services only - $import = $class::load([ - 'object_name' => $name, - 'object_type' => 'template' - ], $connection); - } else { - $import = $class::load($name, $connection); + try { + if (is_array($this->object->getKeyName())) { + // Services only + $import = $class::load([ + 'object_name' => $name, + 'object_type' => 'template' + ], $connection); + } else { + $import = $class::load($name, $connection); + } + } catch (NotFoundError $e) { + throw new NotFoundError(sprintf( + 'Unable to load parent referenced from %s "%s", %s', + $this->object->getShortTableName(), + $this->object->getObjectName(), + lcfirst($e->getMessage()) + ), $e->getCode(), $e); } return $this->objects[$import->getObjectName()] = $import;