Error handling for resetDataUnderPIM API

This commit updates resetDataUnderPIM API to set error code in case of
error. This helps the caller of API to take action based on the error
code returned from the API.

Change-Id: I71427b473d3094d0b2ea357cdde4d6c4d2627d2b
Signed-off-by: Rekha Aparna <vrekhaaparna@ibm.com>
diff --git a/vpd-manager/include/utility/vpd_specific_utility.hpp b/vpd-manager/include/utility/vpd_specific_utility.hpp
index 96edbbc..55fa798 100644
--- a/vpd-manager/include/utility/vpd_specific_utility.hpp
+++ b/vpd-manager/include/utility/vpd_specific_utility.hpp
@@ -633,10 +633,18 @@
  *
  * @param[in] i_objectPath - DBus object path of the FRU.
  * @param[in] io_interfaceMap - Interface and its properties map.
+ * @param[out] o_errCode - To set error code in case of error.
  */
 inline void resetDataUnderPIM(const std::string& i_objectPath,
-                              types::InterfaceMap& io_interfaceMap)
+                              types::InterfaceMap& io_interfaceMap,
+                              uint16_t& o_errCode)
 {
+    if (i_objectPath.empty())
+    {
+        o_errCode = error_code::INVALID_INPUT_PARAMETER;
+        return;
+    }
+
     try
     {
         std::vector<std::string> l_interfaces;
@@ -722,8 +730,7 @@
     }
     catch (const std::exception& l_ex)
     {
-        logging::logMessage("Failed to remove VPD for FRU: " + i_objectPath +
-                            " with error: " + std::string(l_ex.what()));
+        o_errCode = error_code::STANDARD_EXCEPTION;
     }
 }
 
diff --git a/vpd-manager/src/worker.cpp b/vpd-manager/src/worker.cpp
index b04c431..a6970aa 100644
--- a/vpd-manager/src/worker.cpp
+++ b/vpd-manager/src/worker.cpp
@@ -1717,16 +1717,34 @@
                 for (const auto& [l_objectPath, l_serviceInterfaceMap] :
                      l_subTreeMap)
                 {
+                    l_errCode = 0;
                     types::InterfaceMap l_interfaceMap;
-                    vpdSpecificUtility::resetDataUnderPIM(l_objectPath,
-                                                          l_interfaceMap);
+                    vpdSpecificUtility::resetDataUnderPIM(
+                        l_objectPath, l_interfaceMap, l_errCode);
+
+                    if (l_errCode)
+                    {
+                        throw std::runtime_error(
+                            "Failed to reset data under PIM for sub FRU [" +
+                            l_objectPath + "], error : " +
+                            commonUtility::getErrCodeMsg(l_errCode));
+                    }
+
                     l_objectMap.emplace(l_objectPath,
                                         std::move(l_interfaceMap));
                 }
 
+                l_errCode = 0;
                 types::InterfaceMap l_interfaceMap;
-                vpdSpecificUtility::resetDataUnderPIM(i_dbusObjPath,
-                                                      l_interfaceMap);
+                vpdSpecificUtility::resetDataUnderPIM(
+                    i_dbusObjPath, l_interfaceMap, l_errCode);
+
+                if (l_errCode)
+                {
+                    throw std::runtime_error(
+                        "Failed to reset data under PIM, error : " +
+                        commonUtility::getErrCodeMsg(l_errCode));
+                }
 
                 l_objectMap.emplace(i_dbusObjPath, std::move(l_interfaceMap));
 
diff --git a/wait-vpd-parser/src/prime_inventory.cpp b/wait-vpd-parser/src/prime_inventory.cpp
index 137231b..67a6671 100644
--- a/wait-vpd-parser/src/prime_inventory.cpp
+++ b/wait-vpd-parser/src/prime_inventory.cpp
@@ -174,8 +174,18 @@
     if (isPresentPropertyHandlingRequired(i_fruJsonObj))
     {
         // Clear data under PIM if already exists.
+        uint16_t l_errCode = 0;
         vpd::vpdSpecificUtility::resetDataUnderPIM(
-            std::string(i_fruJsonObj["inventoryPath"]), l_interfaces);
+            std::string(i_fruJsonObj["inventoryPath"]), l_interfaces,
+            l_errCode);
+
+        if (l_errCode)
+        {
+            m_logger->logMessage(
+                "Failed to reset data under PIM for path [" +
+                std::string(i_fruJsonObj["inventoryPath"]) +
+                "], error : " + vpd::commonUtility::getErrCodeMsg(l_errCode));
+        }
     }
 
     // Add extra interfaces mentioned in the Json config file