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>
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 @@
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 @@
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 @@
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 ||