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: I6ece20bca5a99da3b7a6f3b6aa55b22842f3b422
diff --git a/src/inventory_mac.cpp b/src/inventory_mac.cpp
index 8d38c37..67e8dff 100644
--- a/src/inventory_mac.cpp
+++ b/src/inventory_mac.cpp
@@ -91,12 +91,17 @@
mapperCall.append(invRoot, depth, interfaces);
- auto mapperReply = bus.call(mapperCall);
- if (mapperReply.is_method_error())
- {
- lg2::error("Error in mapper call");
- elog<InternalFailure>();
- }
+ auto mapperReply = [&]() {
+ try
+ {
+ return bus.call(mapperCall);
+ }
+ catch (const sdbusplus::exception::SdBusError& e)
+ {
+ lg2::error("Error in mapper call");
+ elog<InternalFailure>();
+ }
+ }();
ObjectTree objectTree;
mapperReply.read(objectTree);
@@ -145,14 +150,19 @@
method.append(invNetworkIntf, "MACAddress");
- auto reply = bus.call(method);
- if (reply.is_method_error())
- {
- lg2::error(
- "Failed to get MACAddress for path {DBUS_PATH} interface {DBUS_INTF}",
- "DBUS_PATH", objPath, "DBUS_INTF", invNetworkIntf);
- elog<InternalFailure>();
- }
+ auto reply = [&]() {
+ try
+ {
+ return bus.call(method);
+ }
+ catch (const sdbusplus::exception::SdBusError& e)
+ {
+ lg2::error(
+ "Failed to get MACAddress for path {DBUS_PATH} interface {DBUS_INTF}",
+ "DBUS_PATH", objPath, "DBUS_INTF", invNetworkIntf);
+ elog<InternalFailure>();
+ }
+ }();
std::variant<std::string> value;
reply.read(value);