Error code for getListOfFrusReplaceableAtStandby
This commit updates getListOfFrusReplaceableAtStandby API to set error
code in case of error. This helps caller of API to take action based on
the error code returned from the API.
Change-Id: I54c496f76a0e2079346c8712950ddbce0d855026
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 c0aff71..563842d 100644
--- a/vpd-manager/include/utility/json_utility.hpp
+++ b/vpd-manager/include/utility/json_utility.hpp
@@ -1071,48 +1071,40 @@
* standby.
*
* @param[in] i_sysCfgJsonObj - System config JSON object.
+ * @param[out] o_errCode - To set error code in case of error.
*
* @return - On success, list of FRUs replaceable at standby. On failure, empty
* vector.
*/
inline std::vector<std::string> getListOfFrusReplaceableAtStandby(
- const nlohmann::json& i_sysCfgJsonObj) noexcept
+ const nlohmann::json& i_sysCfgJsonObj, uint16_t& o_errCode)
{
std::vector<std::string> l_frusReplaceableAtStandby;
- try
+ if (!i_sysCfgJsonObj.contains("frus"))
{
- if (!i_sysCfgJsonObj.contains("frus"))
- {
- throw std::runtime_error("Missing frus tag in system config JSON.");
- }
+ o_errCode = error_code::INVALID_JSON;
+ return l_frusReplaceableAtStandby;
+ }
- const nlohmann::json& l_fruList =
- i_sysCfgJsonObj["frus"].get_ref<const nlohmann::json::object_t&>();
+ const nlohmann::json& l_fruList =
+ i_sysCfgJsonObj["frus"].get_ref<const nlohmann::json::object_t&>();
- for (const auto& l_fru : l_fruList.items())
+ for (const auto& l_fru : l_fruList.items())
+ {
+ if (i_sysCfgJsonObj["frus"][l_fru.key()].at(0).value(
+ "replaceableAtStandby", false))
{
- if (i_sysCfgJsonObj["frus"][l_fru.key()].at(0).value(
- "replaceableAtStandby", false))
+ const std::string& l_inventoryObjectPath =
+ i_sysCfgJsonObj["frus"][l_fru.key()].at(0).value(
+ "inventoryPath", "");
+
+ if (!l_inventoryObjectPath.empty())
{
- const std::string& l_inventoryObjectPath =
- i_sysCfgJsonObj["frus"][l_fru.key()].at(0).value(
- "inventoryPath", "");
-
- if (!l_inventoryObjectPath.empty())
- {
- l_frusReplaceableAtStandby.emplace_back(
- l_inventoryObjectPath);
- }
+ l_frusReplaceableAtStandby.emplace_back(l_inventoryObjectPath);
}
}
}
- catch (const std::exception& l_ex)
- {
- logging::logMessage(
- "Failed to get list of FRUs replaceable at standby, error: " +
- std::string(l_ex.what()));
- }
return l_frusReplaceableAtStandby;
}
diff --git a/vpd-manager/src/worker.cpp b/vpd-manager/src/worker.cpp
index 55e6709..15f5a0e 100644
--- a/vpd-manager/src/worker.cpp
+++ b/vpd-manager/src/worker.cpp
@@ -1935,8 +1935,18 @@
"System config json object is empty, can't process recollection.");
}
+ uint16_t l_errCode = 0;
const auto& l_frusReplaceableAtStandby =
- jsonUtility::getListOfFrusReplaceableAtStandby(m_parsedJson);
+ jsonUtility::getListOfFrusReplaceableAtStandby(m_parsedJson,
+ l_errCode);
+
+ if (l_errCode)
+ {
+ logging::logMessage(
+ "Failed to get list of FRUs replaceable at runtime, error : " +
+ vpdSpecificUtility::getErrCodeMsg(l_errCode));
+ return;
+ }
for (const auto& l_fruInventoryPath : l_frusReplaceableAtStandby)
{