Remove is_method_error method
Remove the usage of is_method_error()[1], and 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: I85192219c1c34cf5fd6c6aca06a8b207d7e06697
diff --git a/selutility.cpp b/selutility.cpp
index 3473814..9684b36 100644
--- a/selutility.cpp
+++ b/selutility.cpp
@@ -190,16 +190,19 @@
propIntf, "GetAll");
methodCall.append(logEntryIntf);
- auto reply = bus.call(methodCall);
- if (reply.is_method_error())
+ entryDataMap entryData;
+ try
{
- log<level::ERR>("Error in reading logging property entries");
+ auto reply = bus.call(methodCall);
+ reply.read(entryData);
+ }
+ catch (const std::exception& e)
+ {
+ log<level::ERR>("Error in reading logging property entries",
+ entry("ERROR=%s", e.what()));
elog<InternalFailure>();
}
- entryDataMap entryData;
- reply.read(entryData);
-
// Read Id from the log entry.
static constexpr auto propId = "Id";
auto iterId = entryData.find(propId);
@@ -322,18 +325,21 @@
methodCall.append(assocIntf);
methodCall.append(assocProp);
- auto reply = bus.call(methodCall);
- if (reply.is_method_error())
- {
- log<level::ERR>("Error in reading Associations interface");
- elog<InternalFailure>();
- }
-
using AssociationList =
std::vector<std::tuple<std::string, std::string, std::string>>;
std::variant<AssociationList> list;
- reply.read(list);
+ try
+ {
+ auto reply = bus.call(methodCall);
+ reply.read(list);
+ }
+ catch (const std::exception& e)
+ {
+ log<level::ERR>("Error in reading Associations interface",
+ entry("ERROR=%s", e.what()));
+ elog<InternalFailure>();
+ }
auto& assocs = std::get<AssociationList>(list);
@@ -381,16 +387,19 @@
methodCall.append(logEntryIntf);
methodCall.append(propTimeStamp);
- auto reply = bus.call(methodCall);
- if (reply.is_method_error())
+ std::variant<uint64_t> timeStamp;
+ try
{
- log<level::ERR>("Error in reading Timestamp from Entry interface");
+ auto reply = bus.call(methodCall);
+ reply.read(timeStamp);
+ }
+ catch (const std::exception& e)
+ {
+ log<level::ERR>("Error in reading Timestamp from Entry interface",
+ entry("ERROR=%s", e.what()));
elog<InternalFailure>();
}
- std::variant<uint64_t> timeStamp;
- reply.read(timeStamp);
-
std::chrono::milliseconds chronoTimeStamp(std::get<uint64_t>(timeStamp));
return std::chrono::duration_cast<std::chrono::seconds>(chronoTimeStamp);