Handle D-Bus exceptions
Remove the usage of is_method_error()[1].
Also, add try-catch to handle D-Bus exceptions around mapper call.
[1]https://github.com/openbmc/sdbusplus/commit/079fb85a398d90800935e3985bb1266a7530a26e#diff-945669e8bd9cab4ecc83a574a732921281b2c79eb8bba65efff11736ad18f92bR237-R240
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I85ab0425e441a739966b0a23e46a1974cf67476c
diff --git a/mslverify/util.hpp b/mslverify/util.hpp
index 6ee1e81..d91e5e7 100644
--- a/mslverify/util.hpp
+++ b/mslverify/util.hpp
@@ -4,6 +4,7 @@
#include <phosphor-logging/elog.hpp>
#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/bus.hpp>
+#include <sdbusplus/exception.hpp>
#include <sdbusplus/message.hpp>
#include <xyz/openbmc_project/Common/error.hpp>
@@ -40,16 +41,16 @@
auto reqMsg = bus.new_method_call(busName.c_str(), path.c_str(),
interface.c_str(), method.c_str());
reqMsg.append(std::forward<Args>(args)...);
- auto respMsg = bus.call(reqMsg);
-
- if (respMsg.is_method_error())
+ try
{
- lg2::error("Failed to invoke DBus method. {PATH}, {INTF}, {METHOD}",
+ return bus.call(reqMsg);
+ }
+ catch (const std::exception& e)
+ {
+ lg2::error("Failed to invoke DBus method: {PATH}, {INTF}, {METHOD}",
"PATH", path, "INTF", interface, "METHOD", method);
phosphor::logging::elog<detail::errors::InternalFailure>();
}
-
- return respMsg;
}
/** @brief Invoke a method. */
diff --git a/src/resolve_errors.cpp b/src/resolve_errors.cpp
index fd5be34..a5fd917 100644
--- a/src/resolve_errors.cpp
+++ b/src/resolve_errors.cpp
@@ -90,16 +90,8 @@
std::variant<bool> resolved = true;
- auto response =
- SDBusPlus::callMethod(busName, logEntry, PROPERTY_IFACE, "Set",
- LOGGING_IFACE, RESOLVED_PROPERTY, resolved);
-
- if (response.is_method_error())
- {
- lg2::error(
- "Failed to set Resolved property on an error log entry: {ENTRY}",
- "ENTRY", logEntry);
- }
+ SDBusPlus::callMethod(busName, logEntry, PROPERTY_IFACE, "Set",
+ LOGGING_IFACE, RESOLVED_PROPERTY, resolved);
}
catch (const std::exception& e)
{