Refactor exception handling for writeDbusProperty API

This commit refactors dbus_utility API used to update property value on
DBus to handle any exceptions thrown by it locally and return only
success or failure as the return type.

Also updated the caller of this API to handle the return value.

Change-Id: Ia92c1b0928d02cc0130a8b4e547ba3c6069d0d2f
Signed-off-by: RekhaAparna01 <vrekhaaparna@ibm.com>
diff --git a/vpd-manager/src/bios_handler.cpp b/vpd-manager/src/bios_handler.cpp
index 59094e0..65e0c47 100644
--- a/vpd-manager/src/bios_handler.cpp
+++ b/vpd-manager/src/bios_handler.cpp
@@ -290,19 +290,14 @@
             "xyz.openbmc_project.BIOSConfig.Manager.AttributeType.Integer",
             i_fcoVal.at(constants::VALUE_3))));
 
-    try
-    {
-        dbusUtility::writeDbusProperty(
+    if (!dbusUtility::writeDbusProperty(
             constants::biosConfigMgrService, constants::biosConfigMgrObjPath,
             constants::biosConfigMgrInterface, "PendingAttributes",
-            l_pendingBiosAttribute);
-    }
-    catch (const std::exception& l_ex)
+            l_pendingBiosAttribute))
     {
         // TODO: Should we log informational PEL here as well?
         logging::logMessage(
-            "DBus call to update FCO value in pending attribute failed. " +
-            std::string(l_ex.what()));
+            "DBus call to update FCO value in pending attribute failed. ");
     }
 }
 
@@ -370,19 +365,14 @@
             "xyz.openbmc_project.BIOSConfig.Manager.AttributeType.Enumeration",
             l_valtoUpdate)));
 
-    try
-    {
-        dbusUtility::writeDbusProperty(
+    if (!dbusUtility::writeDbusProperty(
             constants::biosConfigMgrService, constants::biosConfigMgrObjPath,
             constants::biosConfigMgrInterface, "PendingAttributes",
-            l_pendingBiosAttribute);
-    }
-    catch (const std::exception& l_ex)
+            l_pendingBiosAttribute))
     {
         // TODO: Should we log informational PEL here as well?
         logging::logMessage(
-            "DBus call to update AMM value in pending attribute failed. " +
-            std::string(l_ex.what()));
+            "DBus call to update AMM value in pending attribute failed.");
     }
 }
 
@@ -505,18 +495,13 @@
             "xyz.openbmc_project.BIOSConfig.Manager.AttributeType.Enumeration",
             l_valtoUpdate)));
 
-    try
-    {
-        dbusUtility::writeDbusProperty(
+    if (!dbusUtility::writeDbusProperty(
             constants::biosConfigMgrService, constants::biosConfigMgrObjPath,
             constants::biosConfigMgrInterface, "PendingAttributes",
-            l_pendingBiosAttribute);
-    }
-    catch (const std::exception& l_ex)
+            l_pendingBiosAttribute))
     {
         logging::logMessage(
-            "DBus call to update lpar value in pending attribute failed. " +
-            std::string(l_ex.what()));
+            "DBus call to update lpar value in pending attribute failed.");
     }
 
     return;
@@ -621,18 +606,13 @@
             "xyz.openbmc_project.BIOSConfig.Manager.AttributeType.Enumeration",
             l_valtoUpdate)));
 
-    try
-    {
-        dbusUtility::writeDbusProperty(
+    if (!dbusUtility::writeDbusProperty(
             constants::biosConfigMgrService, constants::biosConfigMgrObjPath,
             constants::biosConfigMgrInterface, "PendingAttributes",
-            l_pendingBiosAttribute);
-    }
-    catch (const std::exception& l_ex)
+            l_pendingBiosAttribute))
     {
         logging::logMessage(
-            "DBus call to update NVRAM value in pending attribute failed. " +
-            std::string(l_ex.what()));
+            "DBus call to update NVRAM value in pending attribute failed.");
     }
 }
 
@@ -732,18 +712,13 @@
             "xyz.openbmc_project.BIOSConfig.Manager.AttributeType.Enumeration",
             l_valtoUpdate)));
 
-    try
-    {
-        dbusUtility::writeDbusProperty(
+    if (!dbusUtility::writeDbusProperty(
             constants::biosConfigMgrService, constants::biosConfigMgrObjPath,
             constants::biosConfigMgrInterface, "PendingAttributes",
-            l_pendingBiosAttribute);
-    }
-    catch (const std::exception& l_ex)
+            l_pendingBiosAttribute))
     {
         logging::logMessage(
-            "DBus call to update keep and clear value in pending attribute failed. " +
-            std::string(l_ex.what()));
+            "DBus call to update keep and clear value in pending attribute failed.");
     }
 }
 
diff --git a/vpd-manager/src/manager.cpp b/vpd-manager/src/manager.cpp
index 3ab6ec1..eca1588 100644
--- a/vpd-manager/src/manager.cpp
+++ b/vpd-manager/src/manager.cpp
@@ -543,17 +543,14 @@
 
         // Set CollectionStatus as InProgress. Since it's an intermediate state
         // D-bus set-property call is good enough to update the status.
-        try
-        {
-            const std::string& l_collStatusProp = "CollectionStatus";
-            dbusUtility::writeDbusProperty(
+        const std::string& l_collStatusProp = "CollectionStatus";
+
+        if (!dbusUtility::writeDbusProperty(
                 jsonUtility::getServiceName(l_sysCfgJsonObj,
                                             std::string(i_dbusObjPath)),
                 std::string(i_dbusObjPath), constants::vpdCollectionInterface,
                 l_collStatusProp,
-                types::DbusVariantType{constants::vpdCollectionInProgress});
-        }
-        catch (const std::exception& e)
+                types::DbusVariantType{constants::vpdCollectionInProgress}))
         {
             logging::logMessage(
                 "Unable to set CollectionStatus as InProgress for " +
diff --git a/vpd-manager/src/worker.cpp b/vpd-manager/src/worker.cpp
index 4199c15..1529924 100644
--- a/vpd-manager/src/worker.cpp
+++ b/vpd-manager/src/worker.cpp
@@ -1462,19 +1462,15 @@
 
         if (!l_inventoryPath.empty())
         {
-            try
-            {
-                dbusUtility::writeDbusProperty(
+            if (!dbusUtility::writeDbusProperty(
                     jsonUtility::getServiceName(m_parsedJson, l_inventoryPath),
                     l_inventoryPath, constants::vpdCollectionInterface,
                     "CollectionStatus",
-                    types::DbusVariantType{constants::vpdCollectionInProgress});
-            }
-            catch (const std::exception& l_exception)
+                    types::DbusVariantType{constants::vpdCollectionInProgress}))
             {
                 logging::logMessage(
                     "Unable to set CollectionStatus as InProgress for " +
-                    i_vpdFilePath + ". Error : " + l_exception.what());
+                    i_vpdFilePath + ". Error : " + "DBus write failed");
             }
         }