diff options
author | Anthony Wilson <wilsonan@us.ibm.com> | 2018-10-25 21:56:07 -0500 |
---|---|---|
committer | Anthony Wilson <wilsonan@us.ibm.com> | 2018-11-26 15:12:57 -0600 |
commit | 32c532ea9bcddcab30f4fff30e6938211fdf584d (patch) | |
tree | 49d084e774266d38efdd7a603b8cdf024b56f3b9 /chassis_state_manager.cpp | |
parent | 7a0689a91af664c8485df760bedabba0aef84725 (diff) | |
download | phosphor-state-manager-32c532ea9bcddcab30f4fff30e6938211fdf584d.tar.gz phosphor-state-manager-32c532ea9bcddcab30f4fff30e6938211fdf584d.zip |
Update error handling on sdbusplus calls
Error handling was added to the bus.call() routine,
which effectively deprecated the is_method_error()
check. Errors should now be handled in a try/catch
block.
Change-Id: I1dcbbaa91db443445ef6bb2f616bd37f06731d36
Signed-off-by: Anthony Wilson <wilsonan@us.ibm.com>
Diffstat (limited to 'chassis_state_manager.cpp')
-rw-r--r-- | chassis_state_manager.cpp | 47 |
1 files changed, 11 insertions, 36 deletions
diff --git a/chassis_state_manager.cpp b/chassis_state_manager.cpp index 16cecec..8fd56b8 100644 --- a/chassis_state_manager.cpp +++ b/chassis_state_manager.cpp @@ -70,24 +70,7 @@ void Chassis::determineInitialState() try { auto reply = this->bus.call(method); - if (reply.is_method_error()) - { - log<level::ERR>( - "Error in response message - could not get initial pgood"); - goto fail; - } - - try - { - reply.read(pgood); - } - catch (const SdBusError& e) - { - log<level::ERR>("Error in bus response - bad encoding of pgood", - entry("ERROR=%s", e.what()), - entry("REPLY_SIG=%s", reply.get_signature())); - goto fail; - } + reply.read(pgood); if (sdbusplus::message::variant_ns::get<int>(pgood) == 1) { @@ -165,25 +148,15 @@ bool Chassis::stateActive(const std::string& target) SYSTEMD_INTERFACE, "GetUnit"); method.append(target); - auto result = this->bus.call(method); - - // Check that the bus call didn't result in an error - if (result.is_method_error()) - { - log<level::ERR>("Error in bus call - could not resolve GetUnit for:", - entry(" %s", SYSTEMD_INTERFACE)); - return false; - } try { + auto result = this->bus.call(method); result.read(unitTargetPath); } catch (const SdBusError& e) { - log<level::ERR>("Error in bus response - bad encoding for GetUnit", - entry("ERROR=%s", e.what()), - entry("REPLY_SIG=%s", result.get_signature())); + log<level::ERR>("Error in GetUnit call", entry("ERROR=%s", e.what())); return false; } @@ -193,17 +166,19 @@ bool Chassis::stateActive(const std::string& target) SYSTEMD_PROPERTY_IFACE, "Get"); method.append(SYSTEMD_INTERFACE_UNIT, "ActiveState"); - result = this->bus.call(method); - // Check that the bus call didn't result in an error - if (result.is_method_error()) + try { - log<level::ERR>("Error in bus call - could not resolve Get for:", - entry(" %s", SYSTEMD_PROPERTY_IFACE)); + auto result = this->bus.call(method); + result.read(currentState); + } + catch (const SdBusError& e) + { + log<level::ERR>("Error in ActiveState Get", + entry("ERROR=%s", e.what())); return false; } - result.read(currentState); const auto& currentStateStr = sdbusplus::message::variant_ns::get<std::string>(currentState); return currentStateStr == ACTIVE_STATE || |