Set error code for isFruReplaceableAtRuntime API

This commit updates isFruReplaceableAtRuntime 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: Ibf07dcbce8aaf25a21e851a562914807cec35228
Signed-off-by: Rekha Aparna <vrekhaaparna@ibm.com>
diff --git a/vpd-manager/include/utility/json_utility.hpp b/vpd-manager/include/utility/json_utility.hpp
index 0abbf5b..74dfc38 100644
--- a/vpd-manager/include/utility/json_utility.hpp
+++ b/vpd-manager/include/utility/json_utility.hpp
@@ -1005,35 +1005,31 @@
  *
  * @param[in] i_sysCfgJsonObj - System config JSON object.
  * @param[in] i_vpdFruPath - EEPROM path.
+ * @param[out] o_errCode - to set error code in case of error.
  *
  * @return true if FRU is replaceable at runtime. false otherwise.
  */
 inline bool isFruReplaceableAtRuntime(const nlohmann::json& i_sysCfgJsonObj,
-                                      const std::string& i_vpdFruPath)
+                                      const std::string& i_vpdFruPath,
+                                      uint16_t& o_errCode)
 {
-    try
+    if (i_vpdFruPath.empty())
     {
-        if (i_vpdFruPath.empty())
-        {
-            throw std::runtime_error("Given FRU path is empty.");
-        }
-
-        if (i_sysCfgJsonObj.empty() || (!i_sysCfgJsonObj.contains("frus")))
-        {
-            throw std::runtime_error("Invalid system config JSON object.");
-        }
-
-        return ((i_sysCfgJsonObj["frus"][i_vpdFruPath].at(0))
-                    .contains("replaceableAtRuntime") &&
-                (i_sysCfgJsonObj["frus"][i_vpdFruPath].at(
-                    0)["replaceableAtRuntime"]));
+        o_errCode = error_code::INVALID_INPUT_PARAMETER;
+        return false;
     }
-    catch (const std::exception& l_error)
+
+    if (i_sysCfgJsonObj.empty() || (!i_sysCfgJsonObj.contains("frus")))
     {
-        // TODO: Log PEL
-        logging::logMessage(l_error.what());
+        o_errCode = error_code::INVALID_JSON;
+        return false;
     }
 
+    return (
+        (i_sysCfgJsonObj["frus"][i_vpdFruPath].at(0))
+            .contains("replaceableAtRuntime") &&
+        (i_sysCfgJsonObj["frus"][i_vpdFruPath].at(0)["replaceableAtRuntime"]));
+
     return false;
 }
 
diff --git a/vpd-manager/src/worker.cpp b/vpd-manager/src/worker.cpp
index 2521606..de14c38 100644
--- a/vpd-manager/src/worker.cpp
+++ b/vpd-manager/src/worker.cpp
@@ -1923,8 +1923,21 @@
         // Check if host is up and running
         if (dbusUtility::isHostRunning())
         {
-            if (!jsonUtility::isFruReplaceableAtRuntime(m_parsedJson,
-                                                        l_fruPath))
+            uint16_t l_errCode = 0;
+            bool isFruReplaceableAtRuntime =
+                jsonUtility::isFruReplaceableAtRuntime(m_parsedJson, l_fruPath,
+                                                       l_errCode);
+
+            if (l_errCode)
+            {
+                logging::logMessage(
+                    "Failed to check if FRU is replaceable at runtime for FRU : [" +
+                    std::string(i_dbusObjPath) + "], error : " +
+                    vpdSpecificUtility::getErrCodeMsg(l_errCode));
+                return;
+            }
+
+            if (!isFruReplaceableAtRuntime)
             {
                 logging::logMessage(
                     "Given FRU is not replaceable at host runtime. Single FRU VPD collection is not performed for " +
@@ -1947,9 +1960,21 @@
                     vpdSpecificUtility::getErrCodeMsg(l_errCode));
             }
 
-            if (!isFruReplaceableAtStandby &&
-                (!jsonUtility::isFruReplaceableAtRuntime(m_parsedJson,
-                                                         l_fruPath)))
+            l_errCode = 0;
+            bool isFruReplaceableAtRuntime =
+                jsonUtility::isFruReplaceableAtRuntime(m_parsedJson, l_fruPath,
+                                                       l_errCode);
+
+            if (l_errCode)
+            {
+                logging::logMessage(
+                    "Failed to check if FRU is replaceable at runtime for FRU : [" +
+                    std::string(i_dbusObjPath) + "], error : " +
+                    vpdSpecificUtility::getErrCodeMsg(l_errCode));
+                return;
+            }
+
+            if (!isFruReplaceableAtStandby && (!isFruReplaceableAtRuntime))
             {
                 logging::logMessage(
                     "Given FRU is neither replaceable at standby nor replaceable at runtime. Single FRU VPD collection is not performed for " +