Refactor pass 1 planar API exception handling

This commit refactors vpd specific utility API used to check pass 1
planar, in order to handle any exceptions thrown by it locally. All
utility methods should handle exceptions locally and log a journal log
in case of failure. The caller of the utility APIs should check the
return value to detect success/failure.

Change-Id: I79e38a15ac38e2de9844061c00e7a6d06da6f793
Signed-off-by: Souvik Roy <souvikroyofficial10@gmail.com>
diff --git a/vpd-manager/include/utility/vpd_specific_utility.hpp b/vpd-manager/include/utility/vpd_specific_utility.hpp
index 9bed952..83db199 100644
--- a/vpd-manager/include/utility/vpd_specific_utility.hpp
+++ b/vpd-manager/include/utility/vpd_specific_utility.hpp
@@ -634,39 +634,58 @@
  *
  * @return True if pass 1 planar, false otherwise.
  */
-inline bool isPass1Planar()
+inline bool isPass1Planar() noexcept
 {
-    auto l_retVal = dbusUtility::readDbusProperty(
-        constants::pimServiceName, constants::systemVpdInvPath,
-        constants::viniInf, constants::kwdHW);
-
-    auto l_hwVer = std::get_if<types::BinaryVector>(&l_retVal);
-
-    l_retVal = dbusUtility::readDbusProperty(
-        constants::pimServiceName, constants::systemInvPath, constants::vsbpInf,
-        constants::kwdIM);
-
-    auto l_imValue = std::get_if<types::BinaryVector>(&l_retVal);
-
-    if (l_hwVer && l_imValue)
+    bool l_rc{false};
+    try
     {
-        types::BinaryVector everest{80, 00, 48, 00};
-        types::BinaryVector fuji{96, 00, 32, 00};
+        auto l_retVal = dbusUtility::readDbusProperty(
+            constants::pimServiceName, constants::systemVpdInvPath,
+            constants::viniInf, constants::kwdHW);
 
-        if (((*l_imValue) == everest) || ((*l_imValue) == fuji))
+        auto l_hwVer = std::get_if<types::BinaryVector>(&l_retVal);
+
+        l_retVal = dbusUtility::readDbusProperty(
+            constants::pimServiceName, constants::systemInvPath,
+            constants::vsbpInf, constants::kwdIM);
+
+        auto l_imValue = std::get_if<types::BinaryVector>(&l_retVal);
+
+        if (l_hwVer && l_imValue)
         {
-            if ((*l_hwVer).at(1) < constants::VALUE_21)
+            if (l_hwVer->size() != constants::VALUE_2)
             {
-                return true;
+                throw std::runtime_error("Invalid HW keyword length.");
+            }
+
+            if (l_imValue->size() != constants::VALUE_4)
+            {
+                throw std::runtime_error("Invalid IM keyword length.");
+            }
+
+            const types::BinaryVector l_everest{80, 00, 48, 00};
+            const types::BinaryVector l_fuji{96, 00, 32, 00};
+
+            if (((*l_imValue) == l_everest) || ((*l_imValue) == l_fuji))
+            {
+                if ((*l_hwVer).at(1) < constants::VALUE_21)
+                {
+                    l_rc = true;
+                }
+            }
+            else if ((*l_hwVer).at(1) < constants::VALUE_2)
+            {
+                l_rc = true;
             }
         }
-        else if ((*l_hwVer).at(1) < constants::VALUE_2)
-        {
-            return true;
-        }
+    }
+    catch (const std::exception& l_ex)
+    {
+        logging::logMessage("Failed to check for pass 1 planar. Error: " +
+                            std::string(l_ex.what()));
     }
 
-    return false;
+    return l_rc;
 }
 } // namespace vpdSpecificUtility
 } // namespace vpd