fail-monitor: remove is_method_error call
An `is_method_error` is not appropriate after an sdbus `call` since
`call` will always throw an exception. Remove the pointless call
and instead catch the exception.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I30147723917b0cbcc4b96e1881c8fb3e349e7cb1
diff --git a/fail-monitor/monitor.cpp b/fail-monitor/monitor.cpp
index 6f93841..4547472 100644
--- a/fail-monitor/monitor.cpp
+++ b/fail-monitor/monitor.cpp
@@ -41,17 +41,19 @@
method.append(systemdUnitInterface, "ActiveState");
- auto reply = bus.call(method);
- if (reply.is_method_error())
+ try
+ {
+ auto reply = bus.call(method);
+
+ reply.read(property);
+ }
+ catch (const sdbusplus::exception_t&)
{
log<level::ERR>("Failed reading ActiveState DBus property",
entry("UNIT=%s", source.c_str()));
- // TODO openbmc/openbmc#851 - Once available, throw returned error
- throw std::runtime_error("Failed reading ActiveState DBus property");
+ throw;
}
- reply.read(property);
-
auto value = std::get<std::string>(property);
return (value == failedState);
}
@@ -63,18 +65,19 @@
auto method = bus.new_method_call(systemdService, systemdObjPath,
systemdInterface, "GetUnit");
method.append(source);
- auto reply = bus.call(method);
- if (reply.is_method_error())
+ try
+ {
+ auto reply = bus.call(method);
+ reply.read(path);
+ }
+ catch (const sdbusplus::exception_t&)
{
log<level::ERR>("Failed GetUnit DBus method call",
entry("UNIT=%s", source.c_str()));
- // TODO openbmc/openbmc#851 - Once available, throw returned error
- throw std::runtime_error("Failed GetUnit DBus method call");
+ throw;
}
- reply.read(path);
-
return static_cast<std::string>(path);
}
@@ -95,14 +98,15 @@
method.append(target);
method.append("replace");
- auto reply = bus.call(method);
-
- if (reply.is_method_error())
+ try
+ {
+ auto reply = bus.call(method);
+ }
+ catch (const sdbusplus::exception_t&)
{
log<level::ERR>("Failed to run action on the target unit",
entry("UNIT=%s", target.c_str()));
- // TODO openbmc/openbmc#851 - Once available, throw returned error
- throw std::runtime_error("Failed to run action on the target unit");
+ throw;
}
}
} // namespace failure