IcingaObject/Imports: better error message wording

fixes #2224
This commit is contained in:
Thomas Gelf 2021-01-11 17:32:59 +01:00
parent 0544b57db4
commit 6687524d2f
3 changed files with 28 additions and 9 deletions

View File

@ -14,6 +14,9 @@ next (will be 1.8.1)
### User Interface ### User Interface
* FIX: don't fail when showing a Host overriding multiple inherited groups (#2253) * 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 1.8.0
----- -----

View File

@ -535,7 +535,13 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
$this->connection $this->connection
); );
} catch (NotFoundError $e) { } 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')); $this->reallySet($name, $object->get('id'));

View File

@ -4,6 +4,7 @@ namespace Icinga\Module\Director\Objects;
use Countable; use Countable;
use Exception; use Exception;
use Icinga\Exception\NotFoundError;
use Iterator; use Iterator;
use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c; use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
use Icinga\Module\Director\IcingaConfig\IcingaConfigRenderer; use Icinga\Module\Director\IcingaConfig\IcingaConfigRenderer;
@ -251,14 +252,23 @@ class IcingaObjectImports implements Iterator, Countable, IcingaConfigRenderer
$connection = $this->object->getConnection(); $connection = $this->object->getConnection();
/** @var IcingaObject $class */ /** @var IcingaObject $class */
$class = $this->getImportClass(); $class = $this->getImportClass();
if (is_array($this->object->getKeyName())) { try {
// Services only if (is_array($this->object->getKeyName())) {
$import = $class::load([ // Services only
'object_name' => $name, $import = $class::load([
'object_type' => 'template' 'object_name' => $name,
], $connection); 'object_type' => 'template'
} else { ], $connection);
$import = $class::load($name, $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; return $this->objects[$import->getObjectName()] = $import;