Error code for updateKwdOnInheritedFrus API
This commit updates updateKwdOnInheritedFrus API to set error code in
case of error. This helps the caller of API to take action based on the
error code returned from the API.
Change-Id: I83e67e0c1fb51bbbd6df7ed7f5b01b091dbd2e18
Signed-off-by: Rekha Aparna <vrekhaaparna@ibm.com>
diff --git a/vpd-manager/include/utility/vpd_specific_utility.hpp b/vpd-manager/include/utility/vpd_specific_utility.hpp
index b6d1247..30a3b9a 100644
--- a/vpd-manager/include/utility/vpd_specific_utility.hpp
+++ b/vpd-manager/include/utility/vpd_specific_utility.hpp
@@ -916,24 +916,32 @@
* @param[in] i_fruPath - EEPROM path of FRU.
* @param[in] i_paramsToWriteData - Input details.
* @param[in] i_sysCfgJsonObj - System config JSON.
+ * @param[out] o_errCode - To set error code in case of error.
*
*/
inline void updateKwdOnInheritedFrus(
const std::string& i_fruPath,
const types::WriteVpdParams& i_paramsToWriteData,
- const nlohmann::json& i_sysCfgJsonObj) noexcept
+ const nlohmann::json& i_sysCfgJsonObj, uint16_t& o_errCode) noexcept
{
try
{
+ if (i_fruPath.empty() || i_sysCfgJsonObj.empty())
+ {
+ o_errCode = error_code::INVALID_INPUT_PARAMETER;
+ return;
+ }
+
if (!i_sysCfgJsonObj.contains("frus"))
{
- throw std::runtime_error("Mandatory tag(s) missing from JSON");
+ o_errCode = error_code::INVALID_JSON;
+ return;
}
if (!i_sysCfgJsonObj["frus"].contains(i_fruPath))
{
- throw std::runtime_error(
- "VPD path [" + i_fruPath + "] not found in system config JSON");
+ o_errCode = error_code::FRU_PATH_NOT_FOUND;
+ return;
}
const types::IpzData* l_ipzData =
@@ -941,7 +949,8 @@
if (!l_ipzData)
{
- throw std::runtime_error("Unsupported VPD type");
+ o_errCode = error_code::UNSUPPORTED_VPD_TYPE;
+ return;
}
// iterate through all inventory paths for given EEPROM path,
// except the base FRU.
@@ -977,16 +986,15 @@
// notify PIM
if (!dbusUtility::callPIM(move(l_objectInterfaceMap)))
{
- throw std::runtime_error(
- "Call to PIM failed for VPD file " + i_fruPath);
+ o_errCode = error_code::DBUS_FAILURE;
+ return;
}
}
}
catch (const std::exception& l_ex)
{
- logging::logMessage(
- "Failed to sync keyword update to inherited FRUs of FRU [" +
- i_fruPath + "]. Error: " + std::string(l_ex.what()));
+ o_errCode = error_code::STANDARD_EXCEPTION;
+ return;
}
}
diff --git a/vpd-manager/src/manager.cpp b/vpd-manager/src/manager.cpp
index ca77491..66ba094 100644
--- a/vpd-manager/src/manager.cpp
+++ b/vpd-manager/src/manager.cpp
@@ -259,8 +259,17 @@
// update keyword in inherited FRUs
if (l_rc != constants::FAILURE)
{
+ l_errCode = 0;
vpdSpecificUtility::updateKwdOnInheritedFrus(
- l_fruPath, l_writeParams, l_sysCfgJsonObj);
+ l_fruPath, l_writeParams, l_sysCfgJsonObj, l_errCode);
+
+ if (l_errCode)
+ {
+ logging::logMessage(
+ "Failed to update keyword on inherited FRUs for FRU [" +
+ l_fruPath +
+ "] , error : " + commonUtility::getErrCodeMsg(l_errCode));
+ }
}
// update common interface(s) properties
@@ -273,14 +282,14 @@
// log VPD write success or failure
auto l_logger = Logger::getLoggerInstance();
- uint16_t l_errorCode;
+ l_errCode = 0;
l_logger->logMessage(
"VPD write " +
std::string(
(l_rc != constants::FAILURE) ? "successful" : "failed") +
" on path[" + i_vpdPath + "] : " +
vpdSpecificUtility::convertWriteVpdParamsToString(l_writeParams,
- l_errorCode),
+ l_errCode),
PlaceHolder::VPD_WRITE);
return l_rc;