Error code for insertorMerge API
This commit updates insertOrMerge 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: I4bd37c226a7f2f73076d811e641e39159eadf874
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 55fa798..f2ba545 100644
--- a/vpd-manager/include/utility/vpd_specific_utility.hpp
+++ b/vpd-manager/include/utility/vpd_specific_utility.hpp
@@ -299,14 +299,17 @@
* @param[in,out] io_map - Interface map.
* @param[in] i_interface - Interface to be processed.
* @param[in] i_propertyMap - new property map that needs to be emplaced.
+ * @param[out] o_errCode - To set error code in case of error.
*
* @return On success returns 0, otherwise returns -1.
*/
inline int insertOrMerge(types::InterfaceMap& io_map,
const std::string& i_interface,
- types::PropertyMap&& i_propertyMap) noexcept
+ types::PropertyMap&& i_propertyMap,
+ uint16_t& o_errCode) noexcept
{
int l_rc{constants::FAILURE};
+
try
{
if (io_map.find(i_interface) != io_map.end())
@@ -326,10 +329,7 @@
}
catch (const std::exception& l_ex)
{
- // ToDo:: Log PEL
- logging::logMessage(
- "Inserting properties into interface[" + i_interface +
- "] map failed, reason: " + std::string(l_ex.what()));
+ o_errCode = error_code::STANDARD_EXCEPTION;
}
return l_rc;
}
diff --git a/vpd-manager/src/worker.cpp b/vpd-manager/src/worker.cpp
index a6970aa..373883b 100644
--- a/vpd-manager/src/worker.cpp
+++ b/vpd-manager/src/worker.cpp
@@ -535,8 +535,17 @@
if (!propertyValueMap.empty())
{
+ uint16_t l_errCode = 0;
vpdSpecificUtility::insertOrMerge(
- interfaceMap, constants::kwdVpdInf, move(propertyValueMap));
+ interfaceMap, constants::kwdVpdInf, move(propertyValueMap),
+ l_errCode);
+
+ if (l_errCode)
+ {
+ logging::logMessage(
+ "Failed to insert value into map, error : " +
+ commonUtility::getErrCodeMsg(l_errCode));
+ }
}
}
}
@@ -547,6 +556,7 @@
{
for (const auto& interfacesPropPair : interfaceJson.items())
{
+ uint16_t l_errCode = 0;
const std::string& interface = interfacesPropPair.key();
types::PropertyMap propertyMap;
@@ -574,7 +584,14 @@
vpdSpecificUtility::insertOrMerge(
interfaceMap,
std::string(constants::xyzLocationCodeInf),
- move(l_locCodeProperty));
+ move(l_locCodeProperty), l_errCode);
+
+ if (l_errCode)
+ {
+ logging::logMessage(
+ "Failed to insert value into map, error : " +
+ commonUtility::getErrCodeMsg(l_errCode));
+ }
}
else
{
@@ -694,8 +711,15 @@
}
}
}
+ l_errCode = 0;
vpdSpecificUtility::insertOrMerge(interfaceMap, interface,
- move(propertyMap));
+ move(propertyMap), l_errCode);
+
+ if (l_errCode)
+ {
+ logging::logMessage("Failed to insert value into map, error : " +
+ commonUtility::getErrCodeMsg(l_errCode));
+ }
}
}
@@ -737,10 +761,18 @@
// Check if its required to handle presence for this FRU.
if (singleFru.value("handlePresence", true))
{
+ uint16_t l_errCode = 0;
types::PropertyMap presProp;
presProp.emplace("Present", true);
- vpdSpecificUtility::insertOrMerge(
- interfaces, "xyz.openbmc_project.Inventory.Item", move(presProp));
+ vpdSpecificUtility::insertOrMerge(interfaces,
+ "xyz.openbmc_project.Inventory.Item",
+ move(presProp), l_errCode);
+
+ if (l_errCode)
+ {
+ logging::logMessage("Failed to insert value into map, error : " +
+ commonUtility::getErrCodeMsg(l_errCode));
+ }
}
}
@@ -898,11 +930,19 @@
// Implies value is not there in D-Bus. Populate it with default
// value "true".
+ uint16_t l_errCode = 0;
types::PropertyMap l_functionalProp;
l_functionalProp.emplace("Functional", true);
vpdSpecificUtility::insertOrMerge(io_interfaces,
constants::operationalStatusInf,
- move(l_functionalProp));
+ move(l_functionalProp), l_errCode);
+
+ if (l_errCode)
+ {
+ logging::logMessage(
+ "Failed to insert interface into map, error : " +
+ commonUtility::getErrCodeMsg(l_errCode));
+ }
}
// if chassis is power on. Functional property should be there on D-Bus.
@@ -936,10 +976,18 @@
// Implies value is not there in D-Bus. Populate it with default
// value "true".
+ uint16_t l_errCode = 0;
types::PropertyMap l_enabledProp;
l_enabledProp.emplace("Enabled", true);
vpdSpecificUtility::insertOrMerge(io_interfaces, constants::enableInf,
- move(l_enabledProp));
+ move(l_enabledProp), l_errCode);
+
+ if (l_errCode)
+ {
+ logging::logMessage(
+ "Failed to insert interface into map, error : " +
+ commonUtility::getErrCodeMsg(l_errCode));
+ }
}
// if chassis is power on. Enabled property should be there on D-Bus.
@@ -1837,10 +1885,18 @@
types::PropertyMap l_propertyValueMap;
l_propertyValueMap.emplace("Present", i_value);
+ uint16_t l_errCode = 0;
types::InterfaceMap l_interfaces;
- vpdSpecificUtility::insertOrMerge(l_interfaces,
- constants::inventoryItemInf,
- move(l_propertyValueMap));
+ vpdSpecificUtility::insertOrMerge(
+ l_interfaces, constants::inventoryItemInf,
+ move(l_propertyValueMap), l_errCode);
+
+ if (l_errCode)
+ {
+ logging::logMessage(
+ "Failed to insert value into map, error : " +
+ commonUtility::getErrCodeMsg(l_errCode));
+ }
l_objectInterfaceMap.emplace(std::move(l_fruObjectPath),
std::move(l_interfaces));
@@ -1858,10 +1914,18 @@
types::PropertyMap l_propertyValueMap;
l_propertyValueMap.emplace("Present", i_value);
+ uint16_t l_errCode = 0;
types::InterfaceMap l_interfaces;
- vpdSpecificUtility::insertOrMerge(l_interfaces,
- constants::inventoryItemInf,
- move(l_propertyValueMap));
+ vpdSpecificUtility::insertOrMerge(
+ l_interfaces, constants::inventoryItemInf,
+ move(l_propertyValueMap), l_errCode);
+
+ if (l_errCode)
+ {
+ logging::logMessage(
+ "Failed to insert value into map, error : " +
+ commonUtility::getErrCodeMsg(l_errCode));
+ }
l_objectInterfaceMap.emplace(i_vpdPath, std::move(l_interfaces));
}
@@ -2120,10 +2184,18 @@
l_propertyValueMap.insert(l_timeStampMap.begin(),
l_timeStampMap.end());
+ uint16_t l_errCode = 0;
types::InterfaceMap l_interfaces;
vpdSpecificUtility::insertOrMerge(
l_interfaces, constants::vpdCollectionInterface,
- move(l_propertyValueMap));
+ move(l_propertyValueMap), l_errCode);
+
+ if (l_errCode)
+ {
+ logging::logMessage(
+ "Failed to insert value into map, error : " +
+ commonUtility::getErrCodeMsg(l_errCode));
+ }
l_objectInterfaceMap.emplace(std::move(l_fruObjectPath),
std::move(l_interfaces));
@@ -2144,10 +2216,18 @@
l_propertyValueMap.insert(l_timeStampMap.begin(),
l_timeStampMap.end());
+ uint16_t l_errCode = 0;
types::InterfaceMap l_interfaces;
- vpdSpecificUtility::insertOrMerge(l_interfaces,
- constants::vpdCollectionInterface,
- move(l_propertyValueMap));
+ vpdSpecificUtility::insertOrMerge(
+ l_interfaces, constants::vpdCollectionInterface,
+ move(l_propertyValueMap), l_errCode);
+
+ if (l_errCode)
+ {
+ logging::logMessage(
+ "Failed to insert value into map, error : " +
+ commonUtility::getErrCodeMsg(l_errCode));
+ }
l_objectInterfaceMap.emplace(i_vpdPath, std::move(l_interfaces));
}
diff --git a/wait-vpd-parser/src/prime_inventory.cpp b/wait-vpd-parser/src/prime_inventory.cpp
index 67a6671..eee3a00 100644
--- a/wait-vpd-parser/src/prime_inventory.cpp
+++ b/wait-vpd-parser/src/prime_inventory.cpp
@@ -213,9 +213,17 @@
}*/
}
+ uint16_t l_errCode = 0;
+
vpd::vpdSpecificUtility::insertOrMerge(
l_interfaces, "xyz.openbmc_project.Inventory.Item",
- move(l_propertyValueMap));
+ move(l_propertyValueMap), l_errCode);
+
+ if (l_errCode)
+ {
+ m_logger->logMessage("Failed to insert value into map, error : " +
+ vpd::commonUtility::getErrCodeMsg(l_errCode));
+ }
if (i_fruJsonObj.value("inherit", true) &&
m_sysCfgJsonObj.contains("commonInterfaces"))
@@ -231,9 +239,16 @@
vpd::types::PropertyMap l_fruCollectionProperty = {
{"Status", vpd::constants::vpdCollectionNotStarted}};
+ l_errCode = 0;
vpd::vpdSpecificUtility::insertOrMerge(
l_interfaces, vpd::constants::vpdCollectionInterface,
- std::move(l_fruCollectionProperty));
+ std::move(l_fruCollectionProperty), l_errCode);
+
+ if (l_errCode)
+ {
+ m_logger->logMessage("Failed to insert value into map, error : " +
+ vpd::commonUtility::getErrCodeMsg(l_errCode));
+ }
o_objectInterfaceMap.emplace(std::move(l_fruObjectPath),
std::move(l_interfaces));
@@ -250,6 +265,7 @@
{
const std::string& l_interface = l_interfacesPropPair.key();
vpd::types::PropertyMap l_propertyMap;
+ uint16_t l_errCode = 0;
for (const auto& l_propValuePair : l_interfacesPropPair.value().items())
{
@@ -275,7 +291,14 @@
vpd::vpdSpecificUtility::insertOrMerge(
io_interfaceMap,
std::string(vpd::constants::xyzLocationCodeInf),
- move(l_locCodeProperty));
+ move(l_locCodeProperty), l_errCode);
+
+ if (l_errCode)
+ {
+ m_logger->logMessage(
+ "Failed to insert value into map, error : " +
+ vpd::commonUtility::getErrCodeMsg(l_errCode));
+ }
}
else
{
@@ -398,8 +421,15 @@
}
}
}
+ l_errCode = 0;
vpd::vpdSpecificUtility::insertOrMerge(io_interfaceMap, l_interface,
- move(l_propertyMap));
+ move(l_propertyMap), l_errCode);
+
+ if (l_errCode)
+ {
+ m_logger->logMessage("Failed to insert value into map, error : " +
+ vpd::commonUtility::getErrCodeMsg(l_errCode));
+ }
}
}
@@ -432,11 +462,18 @@
// Implies value is not there in D-Bus. Populate it with default
// value "true".
+ uint16_t l_errCode = 0;
vpd::types::PropertyMap l_functionalProp;
l_functionalProp.emplace("Functional", true);
vpd::vpdSpecificUtility::insertOrMerge(
io_interfaces, vpd::constants::operationalStatusInf,
- move(l_functionalProp));
+ move(l_functionalProp), l_errCode);
+
+ if (l_errCode)
+ {
+ m_logger->logMessage("Failed to insert value into map, error : " +
+ vpd::commonUtility::getErrCodeMsg(l_errCode));
+ }
}
// if chassis is power on. Functional property should be there on D-Bus.
@@ -472,10 +509,18 @@
// Implies value is not there in D-Bus. Populate it with default
// value "true".
+ uint16_t l_errCode = 0;
vpd::types::PropertyMap l_enabledProp;
l_enabledProp.emplace("Enabled", true);
vpd::vpdSpecificUtility::insertOrMerge(
- io_interfaces, vpd::constants::enableInf, move(l_enabledProp));
+ io_interfaces, vpd::constants::enableInf, move(l_enabledProp),
+ l_errCode);
+
+ if (l_errCode)
+ {
+ m_logger->logMessage("Failed to insert value into map, error : " +
+ vpd::commonUtility::getErrCodeMsg(l_errCode));
+ }
}
// if chassis is power on. Enabled property should be there on D-Bus.