control: Be more lenient toward missing sensors
In the cases where the service name of a sensor (i.e. group member) is
known ahead of time, but that service isn't actually running, the code
will try to make a get property call on it anyway and crash. Fix that
by catching the exception and continuing on.
Also, if the same type of service isn't running but is used in an action
that runs on a timer with 'preload_groups' set in the config to have the
code try to get all properties in the groups after each timer
expiration, there will be an exception thrown there too. In that case,
the exception is caught by the sdeventplus handler so the app doesn't
crash, but it prevents the run() call from completing. Catch that
exception as well in Manager::addGroups() so the actions can complete.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: Ifb56333508c3ceb6027e1e004d946c330dbd8634
diff --git a/control/json/manager.cpp b/control/json/manager.cpp
index 9129750..3949e18 100644
--- a/control/json/manager.cpp
+++ b/control/json/manager.cpp
@@ -569,10 +569,16 @@
{
// No object manager interface provided by service?
// Attempt to retrieve property directly
- auto value = util::SDBusPlus::getPropertyVariant<PropertyVariantType>(
- _bus, service, path, intf, prop);
+ try
+ {
+ auto value =
+ util::SDBusPlus::getPropertyVariant<PropertyVariantType>(
+ _bus, service, path, intf, prop);
- setProperty(path, intf, prop, value);
+ setProperty(path, intf, prop, value);
+ }
+ catch (const std::exception& e)
+ {}
return;
}
@@ -690,13 +696,17 @@
{
// No object manager interface provided for group member
// Attempt to retrieve group member property directly
- auto value = util::SDBusPlus::getPropertyVariant<
- PropertyVariantType>(_bus, service, member,
- group.getInterface(),
- group.getProperty());
-
- setProperty(member, group.getInterface(),
- group.getProperty(), value);
+ try
+ {
+ auto value = util::SDBusPlus::getPropertyVariant<
+ PropertyVariantType>(_bus, service, member,
+ group.getInterface(),
+ group.getProperty());
+ setProperty(member, group.getInterface(),
+ group.getProperty(), value);
+ }
+ catch (const std::exception& e)
+ {}
continue;
}