From 911229275728128ec0f6ac044079c61bdd7aeb01 Mon Sep 17 00:00:00 2001 From: Matt Spinler Date: Mon, 24 Sep 2018 11:31:44 -0500 Subject: fault-monitor: Catch GetSubTree exceptions The C++ implementation of the mapper will throw an exception if the passed in interface was not found on any paths, which is expected to happen when fru-fault-monitor checks for error logs on startup and there aren't any. Catch that exception and just continue on the path of there being no error logs. Note this is made slightly more complicated by the fact that the default constructor for sdbusplus::message is deleted, so one cannot just do: sdbusplus::message reply; try { auto method = bus.new_method_call(...); reply = bus.call(method); } ... reply.read(...); Change-Id: Ic15c7112cbfe0f3df974748f90828f12255ec29a Signed-off-by: Matt Spinler --- fault-monitor/fru-fault-monitor.cpp | 49 +++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/fault-monitor/fru-fault-monitor.cpp b/fault-monitor/fru-fault-monitor.cpp index 8f5f8fa..aecb481 100644 --- a/fault-monitor/fru-fault-monitor.cpp +++ b/fault-monitor/fru-fault-monitor.cpp @@ -217,7 +217,7 @@ void Add::created(sdbusplus::message::message& msg) return; } -void Add::processExistingCallouts(sdbusplus::bus::bus& bus) +void getLoggingSubTree(sdbusplus::bus::bus& bus, MapperResponseType& subtree) { auto depth = 0; auto mapperCall = bus.new_method_call(MAPPER_BUSNAME, @@ -228,30 +228,41 @@ void Add::processExistingCallouts(sdbusplus::bus::bus& bus) mapperCall.append(depth); mapperCall.append(std::vector({LOG_IFACE})); - auto mapperResponseMsg = bus.call(mapperCall); - if (mapperResponseMsg.is_method_error()) - { - using namespace xyz::openbmc_project::Led::Mapper; - report( - MethodError::METHOD_NAME("GetSubTree"), - MethodError::PATH(MAPPER_OBJ_PATH), - MethodError::INTERFACE( - OBJMGR_IFACE)); - return; - } - - MapperResponseType mapperResponse; try { - mapperResponseMsg.read(mapperResponse); + auto mapperResponseMsg = bus.call(mapperCall); + if (mapperResponseMsg.is_method_error()) + { + using namespace xyz::openbmc_project::Led::Mapper; + report( + MethodError::METHOD_NAME("GetSubTree"), + MethodError::PATH(MAPPER_OBJ_PATH), + MethodError::INTERFACE(OBJMGR_IFACE)); + return; + } + + try + { + mapperResponseMsg.read(subtree); + } + catch (const sdbusplus::exception::SdBusError& e) + { + log("Failed to parse existing callouts subtree message", + entry("ERROR=%s", e.what()), + entry("REPLY_SIG=%s", mapperResponseMsg.get_signature())); + } } catch (const sdbusplus::exception::SdBusError& e) { - log("Failed to parse existing callouts subtree message", - entry("ERROR=%s", e.what()), - entry("REPLY_SIG=%s", mapperResponseMsg.get_signature())); - return; + // Just means no log entries at the moment } +} + +void Add::processExistingCallouts(sdbusplus::bus::bus& bus) +{ + MapperResponseType mapperResponse; + + getLoggingSubTree(bus, mapperResponse); if (mapperResponse.empty()) { //No errors to process. -- cgit v1.2.1