Update json_utility APIs with error codes

This commit updates API getVPDOffset and getInventoryObjPathFromJson to
set error codes in case of errors/exceptions. This helps caller of the
APIs to take action based on the error code returned from the API.

Change-Id: Icfe2640ee311d61e83ca302e5199ce4dd1057c8b
Signed-off-by: Rekha Aparna <vrekhaaparna@ibm.com>
diff --git a/vpd-manager/src/worker.cpp b/vpd-manager/src/worker.cpp
index 179e7ec..5f8d888 100644
--- a/vpd-manager/src/worker.cpp
+++ b/vpd-manager/src/worker.cpp
@@ -1369,10 +1369,12 @@
         m_activeCollectionThreadCount++;
         m_mutex.unlock();
 
-        // Set collection Status as InProgress. Since it's an intermediate state
+        uint16_t l_errCode = 0;
+
+        // Set CollectionStatus as InProgress. Since it's an intermediate state
         // D-bus set-property call is good enough to update the status.
         l_inventoryPath = jsonUtility::getInventoryObjPathFromJson(
-            m_parsedJson, i_vpdFilePath);
+            m_parsedJson, i_vpdFilePath, l_errCode);
 
         if (!l_inventoryPath.empty())
         {
@@ -1391,6 +1393,12 @@
                     i_vpdFilePath + ". Error : " + "DBus write failed");
             }
         }
+        else if (l_errCode)
+        {
+            logging::logMessage(
+                "Failed to get inventory path for FRU [" + i_vpdFilePath +
+                "], error : " + vpdSpecificUtility::getErrCodeMsg(l_errCode));
+        }
 
         const types::VPDMapVariant& parsedVpdMap = parseVpdFile(i_vpdFilePath);
         if (!std::holds_alternative<std::monostate>(parsedVpdMap))
@@ -1429,15 +1437,25 @@
         // based on status of execution.
         if (typeid(ex) == std::type_index(typeid(DataException)))
         {
+            uint16_t l_errCode = 0;
             // In case of pass1 planar, VPD can be corrupted on PCIe cards. Skip
             // logging error for these cases.
             if (vpdSpecificUtility::isPass1Planar())
             {
+                std::string l_invPath =
+                    jsonUtility::getInventoryObjPathFromJson(
+                        m_parsedJson, i_vpdFilePath, l_errCode);
+
+                if (l_errCode != 0)
+                {
+                    logging::logMessage(
+                        "Failed to get inventory object path from JSON for FRU [" +
+                        i_vpdFilePath + "], error: " +
+                        vpdSpecificUtility::getErrCodeMsg(l_errCode));
+                }
+
                 const std::string& l_invPathLeafValue =
-                    sdbusplus::message::object_path(
-                        jsonUtility::getInventoryObjPathFromJson(m_parsedJson,
-                                                                 i_vpdFilePath))
-                        .filename();
+                    sdbusplus::message::object_path(l_invPath).filename();
 
                 if ((l_invPathLeafValue.find("pcie_card", 0) !=
                      std::string::npos))
@@ -1499,11 +1517,22 @@
             return true;
         }
 
+        uint16_t l_errCode = 0;
+        std::string l_invPath = jsonUtility::getInventoryObjPathFromJson(
+            m_parsedJson, i_vpdFilePath, l_errCode);
+
+        if (l_errCode)
+        {
+            logging::logMessage(
+                "Failed to get inventory path from JSON for FRU [" +
+                i_vpdFilePath +
+                "], error : " + vpdSpecificUtility::getErrCodeMsg(l_errCode));
+
+            return false;
+        }
+
         const std::string& l_invPathLeafValue =
-            sdbusplus::message::object_path(
-                jsonUtility::getInventoryObjPathFromJson(m_parsedJson,
-                                                         i_vpdFilePath))
-                .filename();
+            sdbusplus::message::object_path(l_invPath).filename();
 
         if ((l_invPathLeafValue.find("pcie_card", 0) != std::string::npos))
         {