json: Handle compatible interface not existing yet
Catch the DBusMethodError exception that is thrown when the compatible
interface does not exist on any dbus object yet. When this occurs,
attempt to load the JSON config(s) from the override or default
locations, then wait for the interfacesAdded signal of the compatible
interface if still the JSON config(s) could not be found.
Change-Id: I3059e235b292818119523ed0fb219688141e39db
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/json_config.hpp b/json_config.hpp
index fcb603f..6322e6e 100644
--- a/json_config.hpp
+++ b/json_config.hpp
@@ -105,6 +105,8 @@
*/
JsonConfig(std::function<void()> func) : _loadFunc(func)
{
+ std::vector<std::string> compatObjPaths;
+
_match = std::make_unique<sdbusplus::server::match::match>(
util::SDBusPlus::getBus(),
sdbusplus::bus::match::rules::interfacesAdded() +
@@ -112,7 +114,15 @@
std::bind(&JsonConfig::compatIntfAdded, this,
std::placeholders::_1));
- auto compatObjPaths = getCompatObjPaths();
+ try
+ {
+ compatObjPaths = getCompatObjPaths();
+ }
+ catch (const util::DBusMethodError&)
+ {
+ // Compatible interface does not exist on any dbus object yet
+ }
+
if (!compatObjPaths.empty())
{
for (auto& path : compatObjPaths)