From 2ded5e1e3993913be34e8122f2b835468a2f9e91 Mon Sep 17 00:00:00 2001 From: Adriana Kobylak Date: Tue, 10 Jul 2018 12:55:51 -0500 Subject: 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 --- src/sdbusplus.hpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'src') 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 @@ class SDBusPlus const std::string& interface) { std::vector interfaces{interface}; - - auto object = callMethodAndRead( - MAPPER_BUSNAME, MAPPER_PATH, MAPPER_INTERFACE, "GetObject", path, - interfaces); - std::string name; - if (!object.empty()) + + try { - name = object.begin()->first; + auto object = callMethodAndRead( + 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; } -- cgit v1.2.1