From 56c878d8150c3b4d2e94f07d9f514cc6d6f91676 Mon Sep 17 00:00:00 2001 From: Johannes Schmidt Date: Thu, 26 Feb 2026 14:21:07 +0100 Subject: [PATCH] Improve debug message when dependency child/parent don't exist Previously this didn't print which of host/service is referenced and what the referenced non-existing checkable's name should have been. This commit adds that information. --- lib/icinga/dependency.cpp | 40 +++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/lib/icinga/dependency.cpp b/lib/icinga/dependency.cpp index b88ceafd0..db31bb4c4 100644 --- a/lib/icinga/dependency.cpp +++ b/lib/icinga/dependency.cpp @@ -223,26 +223,46 @@ void Dependency::InitChildParentReferences() Host::Ptr childHost = Host::GetByName(GetChildHostName()); if (childHost) { - if (GetChildServiceName().IsEmpty()) + if (GetChildServiceName().IsEmpty()) { m_Child = childHost; - else + } else { m_Child = childHost->GetServiceByShortName(GetChildServiceName()); + if (!m_Child) { + BOOST_THROW_EXCEPTION(ScriptError( + "Dependency '" + GetName() + "' references child service '" + GetChildServiceName() + "' on '" + + GetChildHostName() + "' which doesn't exist.", + GetDebugInfo() + )); + } + } + } else { + BOOST_THROW_EXCEPTION(ScriptError( + "Dependency '" + GetName() + "' references child host '" + GetChildHostName() + "' which doesn't exist.", + GetDebugInfo() + )); } - if (!m_Child) - BOOST_THROW_EXCEPTION(ScriptError("Dependency '" + GetName() + "' references a child host/service which doesn't exist.", GetDebugInfo())); - Host::Ptr parentHost = Host::GetByName(GetParentHostName()); if (parentHost) { - if (GetParentServiceName().IsEmpty()) + if (GetParentServiceName().IsEmpty()) { m_Parent = parentHost; - else + } else { m_Parent = parentHost->GetServiceByShortName(GetParentServiceName()); + if (!m_Parent) { + BOOST_THROW_EXCEPTION(ScriptError( + "Dependency '" + GetName() + "' references parent service '" + GetParentServiceName() + "' on '" + + GetParentHostName() + "' which doesn't exist.", + GetDebugInfo() + )); + } + } + } else { + BOOST_THROW_EXCEPTION(ScriptError( + "Dependency '" + GetName() + "' references parent host '" + GetParentHostName() + "' which doesn't exist.", + GetDebugInfo() + )); } - - if (!m_Parent) - BOOST_THROW_EXCEPTION(ScriptError("Dependency '" + GetName() + "' references a parent host/service which doesn't exist.", GetDebugInfo())); } void Dependency::OnAllConfigLoaded()