Add error handling wrapper for sdbusplus init
There are several places that (sdbusplus::asio::dbus_interface) iface
throws an unhandled expeciton. This change adds a wrapper to handle
these expection, and cerr a message.
Change-Id: I2964b43844a754c7aba7de40241faf730f908972
Signed-off-by: John Edward Broadbent <jebr@google.com>
diff --git a/src/entity_manager.cpp b/src/entity_manager.cpp
index 6a4580d..af229d3 100644
--- a/src/entity_manager.cpp
+++ b/src/entity_manager.cpp
@@ -83,6 +83,21 @@
const std::regex illegalDbusPathRegex("[^A-Za-z0-9_.]");
const std::regex illegalDbusMemberRegex("[^A-Za-z0-9_]");
+void tryIfaceInitialize(std::shared_ptr<sdbusplus::asio::dbus_interface>& iface)
+{
+ try
+ {
+ iface->initialize();
+ }
+ catch (std::exception& e)
+ {
+ std::cerr << "Unable to initialize dbus interface : " << e.what()
+ << "\n"
+ << "object Path : " << iface->get_object_path() << "\n"
+ << "interface name : " << iface->get_interface_name() << "\n";
+ }
+}
+
FoundProbeTypeT findProbeType(const std::string& probe)
{
boost::container::flat_map<const char*, probe_type_codes,
@@ -423,7 +438,7 @@
createDeleteObjectMethod(jsonPointerPath, iface, objServer,
systemConfiguration);
}
- iface->initialize();
+ tryIfaceInitialize(iface);
}
sdbusplus::asio::PropertyPermission getPermission(const std::string& interface)
@@ -559,7 +574,7 @@
interface, newData, objServer,
sdbusplus::asio::PropertyPermission::readWrite);
});
- iface->initialize();
+ tryIfaceInitialize(iface);
}
void postToDbus(const nlohmann::json& newConfiguration,
@@ -803,7 +818,7 @@
findBoard->second);
ifacePtr->register_property("Associations", assocPropValue);
- ifacePtr->initialize();
+ tryIfaceInitialize(ifacePtr);
}
}
@@ -1292,7 +1307,7 @@
entityIface->register_method("ReScan", [&]() {
propertiesChangedCallback(systemConfiguration, objServer);
});
- entityIface->initialize();
+ tryIfaceInitialize(entityIface);
if (fwVersionIsSame())
{