Fix for deserialize cereal exception
This commit provides a fix for an issue in which the cereal
deserialize() would crash the phosphor-host-state-manager,
incase persistence file is empty in restore path.
Change-Id: I5f7774166b5a719fa035b2a2cd4f041303a1e6bf
Signed-off-by: Jayanth Othayoth <ojayanth@in.ibm.com>
diff --git a/host_state_manager.cpp b/host_state_manager.cpp
index 0991cf7..ab60030 100644
--- a/host_state_manager.cpp
+++ b/host_state_manager.cpp
@@ -297,14 +297,23 @@
bool Host::deserialize(const fs::path& path)
{
- if (fs::exists(path))
+ try
{
- std::ifstream is(path.c_str(), std::ios::in | std::ios::binary);
- cereal::JSONInputArchive iarchive(is);
- iarchive(*this);
- return true;
+ if (fs::exists(path))
+ {
+ std::ifstream is(path.c_str(), std::ios::in | std::ios::binary);
+ cereal::JSONInputArchive iarchive(is);
+ iarchive(*this);
+ return true;
+ }
+ return false;
}
- return false;
+ catch(cereal::Exception& e)
+ {
+ log<level::ERR>(e.what());
+ fs::remove(path);
+ return false;
+ }
}
Host::Transition Host::requestedHostTransition(Transition value)