phosphor-inventory: Fix for deserialize cereal exception

This commit provides a fix for an issue in which the cereal
deserialize() would crash the phosphor-inventory, incase
persistence file is empty in restore path.

Change-Id: Id1d40a0e401af8acea92775d1f3337c8a897a7ec
Signed-off-by: Jayanth Othayoth <ojayanth@in.ibm.com>
diff --git a/serialize.hpp b/serialize.hpp
index 7c30b9c..7d0b10e 100644
--- a/serialize.hpp
+++ b/serialize.hpp
@@ -5,6 +5,8 @@
 #include <fstream>
 #include "config.h"
 
+#include <phosphor-logging/log.hpp>
+
 namespace cereal
 {
 
@@ -12,6 +14,7 @@
 
 using Path = std::string;
 using Interface = std::string;
+using namespace phosphor::logging;
 
 /** @brief Serialize inventory item
  *
@@ -44,11 +47,19 @@
     fs::path p(PIM_PERSIST_PATH);
     p /= path;
     p /= iface;
-    if (fs::exists(p))
+    try
     {
-        std::ifstream is(p, std::ios::in | std::ios::binary);
-        cereal::JSONInputArchive iarchive(is);
-        iarchive(object);
+        if (fs::exists(p))
+        {
+            std::ifstream is(p, std::ios::in | std::ios::binary);
+            cereal::JSONInputArchive iarchive(is);
+            iarchive(object);
+        }
+    }
+    catch(cereal::Exception& e)
+    {
+        log<level::ERR>(e.what());
+        fs::remove(p);
     }
 }