From 5739ac3b37ffa3fc32664afdd5aa9ef8f5cf2aa0 Mon Sep 17 00:00:00 2001 From: Patrick Venture Date: Tue, 16 Oct 2018 19:17:41 -0700 Subject: writefrudata: catch exceptions in sdbusplus call Catch sdbusplus call exceptions. Change-Id: Iff0b2a4265061c90ebac78f90e4183f5e36037ef Signed-off-by: Patrick Venture --- writefrudata.cpp | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/writefrudata.cpp b/writefrudata.cpp index 371fa6c..2bbf48e 100644 --- a/writefrudata.cpp +++ b/writefrudata.cpp @@ -16,11 +16,13 @@ #include #include #include +#include #include #include #include using namespace ipmi::vpd; +using namespace phosphor::logging; extern const FruMap frus; extern const std::map extras; @@ -265,15 +267,19 @@ auto getService(sdbusplus::bus::bus& bus, const std::string& intf, mapperCall.append(path); mapperCall.append(std::vector({intf})); + std::map> mapperResponse; - auto mapperResponseMsg = bus.call(mapperCall); - if (mapperResponseMsg.is_method_error()) + try { - throw std::runtime_error("ERROR in mapper call"); + auto mapperResponseMsg = bus.call(mapperCall); + mapperResponseMsg.read(mapperResponse); + } + catch (const sdbusplus::exception::SdBusError& ex) + { + log("Exception from sdbus call", + entry("WHAT=%s", ex.what())); + throw; } - - std::map> mapperResponse; - mapperResponseMsg.read(mapperResponse); if (mapperResponse.begin() == mapperResponse.end()) { @@ -325,7 +331,7 @@ int ipmi_update_inventory(fru_area_vec_t& area_vec, sd_bus* bus_sd) { service = getService(bus, intf, path); } - catch (const std::runtime_error& e) + catch (const std::exception& e) { std::cerr << e.what() << "\n"; return -1; @@ -403,12 +409,17 @@ int ipmi_update_inventory(fru_area_vec_t& area_vec, sd_bus* bus_sd) auto pimMsg = bus.new_method_call(service.c_str(), path.c_str(), intf.c_str(), "Notify"); pimMsg.append(std::move(objects)); - auto inventoryMgrResponseMsg = bus.call(pimMsg); - if (inventoryMgrResponseMsg.is_method_error()) + + try { - std::cerr << "Error in notify call\n"; + auto inventoryMgrResponseMsg = bus.call(pimMsg); + } + catch (const sdbusplus::exception::SdBusError& ex) + { + log("Error in notify call", entry("WHAT=%s", ex.what())); return -1; } + return rc; } -- cgit v1.2.1