diff options
| author | Adriana Kobylak <anoo@us.ibm.com> | 2019-05-31 09:58:04 -0500 |
|---|---|---|
| committer | Adriana Kobylak <anoo@us.ibm.com> | 2019-06-03 14:42:44 -0500 |
| commit | b8cb0cc9d9b3253df47bf019a8f028f01110f9ab (patch) | |
| tree | cda0617a5cfd1bbfaba179c02dfcb8c3a17685d8 | |
| parent | 2b2d2298f5c6e9e596ed3ae84326a6ae804c46a4 (diff) | |
| download | openpower-pnor-code-mgmt-b8cb0cc9d9b3253df47bf019a8f028f01110f9ab.tar.gz openpower-pnor-code-mgmt-b8cb0cc9d9b3253df47bf019a8f028f01110f9ab.zip | |
Remove deprecated is_method_error code
The is_method_error() function is no longer needed, instead a
try-catch block should be used instead.
Reference:
https://lists.ozlabs.org/pipermail/openbmc/2018-October/013696.html
Tested: Code update with field mode enabled, and ran Delete while
host powered on, to check things still worked as expected.
Change-Id: I8ba8da32fe787c3151cc5be7cb9f55d1901e57cd
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
| -rw-r--r-- | activation.cpp | 49 | ||||
| -rw-r--r-- | item_updater.cpp | 41 |
2 files changed, 50 insertions, 40 deletions
diff --git a/activation.cpp b/activation.cpp index b9cd5ba7d..dd52fb681 100644 --- a/activation.cpp +++ b/activation.cpp @@ -106,18 +106,23 @@ void Activation::deleteImageManagerObject() method.append(path); method.append(std::vector<std::string>({deleteInterface})); - auto mapperResponseMsg = bus.call(method); - if (mapperResponseMsg.is_method_error()) + + std::map<std::string, std::vector<std::string>> mapperResponse; + + try { - log<level::ERR>("Error in Get Delete Object", - entry("VERSIONPATH=%s", path.c_str())); - return; + auto mapperResponseMsg = bus.call(method); + mapperResponseMsg.read(mapperResponse); + if (mapperResponse.begin() == mapperResponse.end()) + { + log<level::ERR>("ERROR in reading the mapper response", + entry("VERSIONPATH=%s", path.c_str())); + return; + } } - std::map<std::string, std::vector<std::string>> mapperResponse; - mapperResponseMsg.read(mapperResponse); - if (mapperResponse.begin() == mapperResponse.end()) + catch (const SdBusError& e) { - log<level::ERR>("ERROR in reading the mapper response", + log<level::ERR>("Error in Get Delete Object", entry("VERSIONPATH=%s", path.c_str())); return; } @@ -143,15 +148,7 @@ void Activation::deleteImageManagerObject() deleteInterface, "Delete"); try { - mapperResponseMsg = bus.call(method); - - // Check that the bus call didn't result in an error - if (mapperResponseMsg.is_method_error()) - { - log<level::ERR>("Error in Deleting image from image manager", - entry("VERSIONPATH=%s", path.c_str())); - return; - } + bus.call(method); } catch (const SdBusError& e) { @@ -216,16 +213,20 @@ bool Activation::fieldModeEnabled() "org.freedesktop.DBus.Properties", "Get"); method.append(FIELDMODE_INTERFACE, "FieldModeEnabled"); - auto reply = bus.call(method); - if (reply.is_method_error()) + + sdbusplus::message::variant<bool> fieldMode; + + try + { + auto reply = bus.call(method); + reply.read(fieldMode); + return sdbusplus::message::variant_ns::get<bool>(fieldMode); + } + catch (const SdBusError& e) { log<level::ERR>("Error in fieldModeEnabled getValue"); elog<InternalFailure>(); } - sdbusplus::message::variant<bool> fieldMode; - reply.read(fieldMode); - - return sdbusplus::message::variant_ns::get<bool>(fieldMode); } #endif diff --git a/item_updater.cpp b/item_updater.cpp index f321b02be..882acbbb7 100644 --- a/item_updater.cpp +++ b/item_updater.cpp @@ -214,18 +214,22 @@ bool ItemUpdater::isChassisOn() mapperCall.append(CHASSIS_STATE_PATH, std::vector<std::string>({CHASSIS_STATE_OBJ})); - auto mapperResponseMsg = bus.call(mapperCall); - if (mapperResponseMsg.is_method_error()) + + std::map<std::string, std::vector<std::string>> mapperResponse; + + try { - log<level::ERR>("Error in Mapper call"); - elog<InternalFailure>(); + auto mapperResponseMsg = bus.call(mapperCall); + mapperResponseMsg.read(mapperResponse); + if (mapperResponse.empty()) + { + log<level::ERR>("Invalid Response from mapper"); + elog<InternalFailure>(); + } } - using MapperResponseType = std::map<std::string, std::vector<std::string>>; - MapperResponseType mapperResponse; - mapperResponseMsg.read(mapperResponse); - if (mapperResponse.empty()) + catch (const sdbusplus::exception::SdBusError& e) { - log<level::ERR>("Invalid Response from mapper"); + log<level::ERR>("Error in Mapper call"); elog<InternalFailure>(); } @@ -233,19 +237,24 @@ bool ItemUpdater::isChassisOn() CHASSIS_STATE_PATH, SYSTEMD_PROPERTY_INTERFACE, "Get"); method.append(CHASSIS_STATE_OBJ, "CurrentPowerState"); - auto response = bus.call(method); - if (response.is_method_error()) + + sdbusplus::message::variant<std::string> currentChassisState; + + try + { + auto response = bus.call(method); + response.read(currentChassisState); + auto strParam = sdbusplus::message::variant_ns::get<std::string>( + currentChassisState); + return (strParam != CHASSIS_STATE_OFF); + } + catch (const sdbusplus::exception::SdBusError& e) { log<level::ERR>("Error in fetching current Chassis State", entry("MAPPERRESPONSE=%s", (mapperResponse.begin()->first).c_str())); elog<InternalFailure>(); } - sdbusplus::message::variant<std::string> currentChassisState; - response.read(currentChassisState); - auto strParam = - sdbusplus::message::variant_ns::get<std::string>(currentChassisState); - return (strParam != CHASSIS_STATE_OFF); } } // namespace updater |

