Set error code for isActionRequired API

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

Change-Id: Ib706a3491b502ea9016bf327a6487e98a96c1ea8
Signed-off-by: Rekha Aparna <vrekhaaparna@ibm.com>
diff --git a/vpd-manager/src/worker.cpp b/vpd-manager/src/worker.cpp
index b725745..7a4ce00 100644
--- a/vpd-manager/src/worker.cpp
+++ b/vpd-manager/src/worker.cpp
@@ -1284,6 +1284,8 @@
 {
     try
     {
+        uint16_t l_errCode = 0;
+
         if (i_vpdFilePath.empty())
         {
             throw std::runtime_error(
@@ -1293,10 +1295,10 @@
 
         bool isPreActionRequired = false;
         if (jsonUtility::isActionRequired(m_parsedJson, i_vpdFilePath,
-                                          "preAction", "collection"))
+                                          "preAction", "collection", l_errCode))
         {
+            l_errCode = 0;
             isPreActionRequired = true;
-            uint16_t l_errCode = 0;
             if (!processPreAction(i_vpdFilePath, "collection", l_errCode))
             {
                 if (l_errCode == error_code::DEVICE_NOT_PRESENT)
@@ -1315,6 +1317,13 @@
                     vpdSpecificUtility::getErrCodeMsg(l_errCode));
             }
         }
+        else if (l_errCode)
+        {
+            logging::logMessage(
+                "Failed to check if pre action required for FRU [" +
+                i_vpdFilePath +
+                "], error : " + vpdSpecificUtility::getErrCodeMsg(l_errCode));
+        }
 
         if (!std::filesystem::exists(i_vpdFilePath))
         {
@@ -1336,8 +1345,11 @@
         // any post action in the flow of collection.
         // Note: Don't change the order, post action needs to be processed only
         // after collection for FRU is successfully done.
+        l_errCode = 0;
+
         if (jsonUtility::isActionRequired(m_parsedJson, i_vpdFilePath,
-                                          "postAction", "collection"))
+                                          "postAction", "collection",
+                                          l_errCode))
         {
             if (!processPostAction(i_vpdFilePath, "collection", l_parsedVpd))
             {
@@ -1351,6 +1363,13 @@
                     std::nullopt, std::nullopt, std::nullopt, std::nullopt);
             }
         }
+        else if (l_errCode)
+        {
+            logging::logMessage(
+                "Error while checking if post action required for FRU [" +
+                i_vpdFilePath +
+                "], error : " + vpdSpecificUtility::getErrCodeMsg(l_errCode));
+        }
 
         return l_parsedVpd;
     }
@@ -1363,7 +1382,8 @@
 
         // If post fail action is required, execute it.
         if (jsonUtility::isActionRequired(m_parsedJson, i_vpdFilePath,
-                                          "postFailAction", "collection"))
+                                          "postFailAction", "collection",
+                                          l_errCode))
         {
             if (!jsonUtility::executePostFailAction(m_parsedJson, i_vpdFilePath,
                                                     "collection", l_errCode))
@@ -1373,6 +1393,12 @@
                            " Aborting collection for this FRU.";
             }
         }
+        else if (l_errCode)
+        {
+            l_exMsg +=
+                ". Failed to check if post fail action required, error : " +
+                vpdSpecificUtility::getErrCodeMsg(l_errCode);
+        }
 
         if (typeid(l_ex) == typeid(DataException))
         {
@@ -1702,9 +1728,9 @@
             else
             {
                 if (jsonUtility::isActionRequired(m_parsedJson, l_fruPath,
-                                                  "preAction", "deletion"))
+                                                  "preAction", "deletion",
+                                                  l_errCode))
                 {
-                    uint16_t l_errCode = 0;
                     if (!processPreAction(l_fruPath, "deletion", l_errCode))
                     {
                         std::string l_msg = "Pre action failed";
@@ -1717,6 +1743,13 @@
                         throw std::runtime_error(l_msg);
                     }
                 }
+                else if (l_errCode)
+                {
+                    logging::logMessage(
+                        "Failed to check if pre action required for FRU [" +
+                        l_fruPath + "], error : " +
+                        vpdSpecificUtility::getErrCodeMsg(l_errCode));
+                }
 
                 std::vector<std::string> l_interfaceList{
                     constants::operationalStatusInf};
@@ -1750,14 +1783,24 @@
                     throw std::runtime_error("Call to PIM failed.");
                 }
 
+                l_errCode = 0;
+
                 if (jsonUtility::isActionRequired(m_parsedJson, l_fruPath,
-                                                  "postAction", "deletion"))
+                                                  "postAction", "deletion",
+                                                  l_errCode))
                 {
                     if (!processPostAction(l_fruPath, "deletion"))
                     {
                         throw std::runtime_error("Post action failed");
                     }
                 }
+                else if (l_errCode)
+                {
+                    logging::logMessage(
+                        "Failed to check if post action required during deletion for FRU [" +
+                        l_fruPath + "], error : " +
+                        vpdSpecificUtility::getErrCodeMsg(l_errCode));
+                }
             }
         }
         else
@@ -1779,7 +1822,8 @@
             " error: " + std::string(l_ex.what());
 
         if (jsonUtility::isActionRequired(m_parsedJson, l_fruPath,
-                                          "postFailAction", "deletion"))
+                                          "postFailAction", "deletion",
+                                          l_errCode))
         {
             if (!jsonUtility::executePostFailAction(m_parsedJson, l_fruPath,
                                                     "deletion", l_errCode))
@@ -1788,6 +1832,12 @@
                             vpdSpecificUtility::getErrCodeMsg(l_errCode);
             }
         }
+        else if (l_errCode)
+        {
+            l_errMsg +=
+                ". Failed to check if post fail action required, error : " +
+                vpdSpecificUtility::getErrCodeMsg(l_errCode);
+        }
 
         logging::logMessage(l_errMsg);
     }