Set error code for executePostFailAction API
This commit updates executePostFailAction API to set error code in case
of error. This helps caller of the API to take action based on the
error code returned from the API.
Change-Id: Iaec2506e62307bb041d7b37469d0e4b6b75741f1
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 cf76a00..0abbf5b 100644
--- a/vpd-manager/include/utility/json_utility.hpp
+++ b/vpd-manager/include/utility/json_utility.hpp
@@ -208,51 +208,42 @@
* @param[in] i_parsedConfigJson - config JSON
* @param[in] i_vpdFilePath - EEPROM file path
* @param[in] i_flagToProcess - To identify which flag(s) needs to be processed
+ * @param[out] o_errCode - To set error code in case of error
* under PostFailAction tag of config JSON.
* @return - success or failure
*/
-inline bool executePostFailAction(const nlohmann::json& i_parsedConfigJson,
- const std::string& i_vpdFilePath,
- const std::string& i_flagToProcess)
+inline bool executePostFailAction(
+ const nlohmann::json& i_parsedConfigJson, const std::string& i_vpdFilePath,
+ const std::string& i_flagToProcess, uint16_t& o_errCode)
{
- try
+ if (i_parsedConfigJson.empty() || i_vpdFilePath.empty() ||
+ i_flagToProcess.empty())
{
- if (i_parsedConfigJson.empty() || i_vpdFilePath.empty() ||
- i_flagToProcess.empty())
- {
- throw std::runtime_error(
- "Invalid parameters. Abort processing for post fail action");
- }
+ o_errCode = error_code::INVALID_INPUT_PARAMETER;
+ return false;
+ }
- if (!(i_parsedConfigJson["frus"][i_vpdFilePath].at(0))["postFailAction"]
- .contains(i_flagToProcess))
- {
- throw std::runtime_error(
- "Config JSON missing flag " + i_flagToProcess +
- " to execute post fail action for path = " + i_vpdFilePath);
- }
+ if (!(i_parsedConfigJson["frus"][i_vpdFilePath].at(0))["postFailAction"]
+ .contains(i_flagToProcess))
+ {
+ o_errCode = error_code::MISSING_FLAG;
+ return false;
+ }
- for (const auto& l_tags : (i_parsedConfigJson["frus"][i_vpdFilePath].at(
- 0))["postFailAction"][i_flagToProcess]
- .items())
+ for (const auto& l_tags : (i_parsedConfigJson["frus"][i_vpdFilePath].at(
+ 0))["postFailAction"][i_flagToProcess]
+ .items())
+ {
+ auto itrToFunction = funcionMap.find(l_tags.key());
+ if (itrToFunction != funcionMap.end())
{
- auto itrToFunction = funcionMap.find(l_tags.key());
- if (itrToFunction != funcionMap.end())
+ if (!itrToFunction->second(i_parsedConfigJson, i_vpdFilePath,
+ "postFailAction", i_flagToProcess))
{
- if (!itrToFunction->second(i_parsedConfigJson, i_vpdFilePath,
- "postFailAction", i_flagToProcess))
- {
- return false;
- }
+ return false;
}
}
}
- catch (const std::exception& l_ex)
- {
- logging::logMessage("Execute post fail action failed. Error : " +
- std::string(l_ex.what()));
- return false;
- }
return true;
}
diff --git a/vpd-manager/src/worker.cpp b/vpd-manager/src/worker.cpp
index ca9df5a..2521606 100644
--- a/vpd-manager/src/worker.cpp
+++ b/vpd-manager/src/worker.cpp
@@ -1342,6 +1342,7 @@
}
catch (std::exception& l_ex)
{
+ uint16_t l_errCode = 0;
std::string l_exMsg{
std::string(__FUNCTION__) + " : VPD parsing failed for " +
i_vpdFilePath + " due to error: " + l_ex.what()};
@@ -1351,10 +1352,11 @@
"postFailAction", "collection"))
{
if (!jsonUtility::executePostFailAction(m_parsedJson, i_vpdFilePath,
- "collection"))
+ "collection", l_errCode))
{
- l_exMsg +=
- ". Post Fail Action also failed, aborting collection for this FRU";
+ l_exMsg += ". Post fail action also failed. Error : " +
+ vpdSpecificUtility::getErrCodeMsg(l_errCode) +
+ " Aborting collection for this FRU.";
}
}
@@ -1768,19 +1770,23 @@
}
catch (const std::exception& l_ex)
{
+ uint16_t l_errCode = 0;
+ std::string l_errMsg =
+ "Failed to delete VPD for FRU : " + i_dbusObjPath +
+ " error: " + std::string(l_ex.what());
+
if (jsonUtility::isActionRequired(m_parsedJson, l_fruPath,
"postFailAction", "deletion"))
{
if (!jsonUtility::executePostFailAction(m_parsedJson, l_fruPath,
- "deletion"))
+ "deletion", l_errCode))
{
- logging::logMessage(
- "Post fail action failed for: " + i_dbusObjPath);
+ l_errMsg += ". Post fail action also failed, error : " +
+ vpdSpecificUtility::getErrCodeMsg(l_errCode);
}
}
- logging::logMessage("Failed to delete VPD for FRU : " + i_dbusObjPath +
- " error: " + std::string(l_ex.what()));
+ logging::logMessage(l_errMsg);
}
}