control: Enhance handling exceptions restoring `Current` mode property
Enhance the log message when an exception is thrown while attempting to
restore the `Current` mode property and include possible error code from
removing the file containing the persisted `Current` mode property
value instead of having a possible exception thrown.
Change-Id: I1306a6b8a07f9294fb5815f1e17e2e0fb1b21432
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/json/dbus_zone.cpp b/control/json/dbus_zone.cpp
index 03cb0da..af37108 100644
--- a/control/json/dbus_zone.cpp
+++ b/control/json/dbus_zone.cpp
@@ -20,6 +20,8 @@
#include "sdbusplus.hpp"
#include "zone.hpp"
+#include <fmt/format.h>
+
#include <cereal/archives/json.hpp>
#include <cereal/cereal.hpp>
#include <phosphor-logging/log.hpp>
@@ -85,8 +87,14 @@
}
catch (std::exception& e)
{
- log<level::ERR>(e.what());
- fs::remove(path);
+ // Include possible exception when removing file, otherwise ec = 0
+ std::error_code ec;
+ fs::remove(path, ec);
+ log<level::ERR>(
+ fmt::format("Unable to restore persisted `Current` thermal mode "
+ "property ({}, ec: {})",
+ e.what(), ec.value())
+ .c_str());
current = ThermalModeIntf::current();
}