sdbusplus: Improve error handling
Ignore exceptions from sdbusplus for objects that are queried
as part of a property watch but are expected to be missing
when the BMC starts up.
Tested: The phosphor-dbus-monitor app does not core dump
with the latest sdbusplus changes.
Change-Id: I0f6a850f0e426478bd1ccacb910a44079b9c8a54
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/src/sdbusplus.hpp b/src/sdbusplus.hpp
index f37f7de..0a8e715 100644
--- a/src/sdbusplus.hpp
+++ b/src/sdbusplus.hpp
@@ -102,15 +102,23 @@
const std::string& interface)
{
std::vector<std::string> interfaces{interface};
-
- auto object = callMethodAndRead<GetObject>(
- MAPPER_BUSNAME, MAPPER_PATH, MAPPER_INTERFACE, "GetObject", path,
- interfaces);
-
std::string name;
- if (!object.empty())
+
+ try
{
- name = object.begin()->first;
+ auto object = callMethodAndRead<GetObject>(
+ MAPPER_BUSNAME, MAPPER_PATH, MAPPER_INTERFACE, "GetObject",
+ path, interfaces);
+
+ if (!object.empty())
+ {
+ name = object.begin()->first;
+ }
+ }
+ catch (const SdBusError& e)
+ {
+ // Empty responses are expected sometimes, and the calling
+ // code is set up to handle it.
}
return name;
}