Error code for getCcinFromDbus API
This commit updates getCcinFromDbus 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: I0ff936ca3486c09921ab0d8deb61814d07ce70d3
Signed-off-by: Rekha Aparna <vrekhaaparna@ibm.com>
diff --git a/vpd-manager/include/error_codes.hpp b/vpd-manager/include/error_codes.hpp
index b602fa7..6b4eb76 100644
--- a/vpd-manager/include/error_codes.hpp
+++ b/vpd-manager/include/error_codes.hpp
@@ -40,7 +40,8 @@
OUT_OF_BOUND_EXCEPTION,
FAILED_TO_DETECT_LOCATION_CODE_TYPE,
RECEIVED_INVALID_KWD_TYPE_FROM_DBUS,
- INVALID_KEYWORD_LENGTH
+ INVALID_KEYWORD_LENGTH,
+ INVALID_VALUE_READ_FROM_DBUS
};
const std::unordered_map<int, std::string> errorCodeMap = {
@@ -76,6 +77,7 @@
{error_code::STANDARD_EXCEPTION, "Standard Exception thrown"},
{error_code::FILE_SYSTEM_ERROR, "File system error."},
{error_code::INVALID_KEYWORD_LENGTH, "Invalid keyword length."},
+ {error_code::INVALID_VALUE_READ_FROM_DBUS, "Invalid value read from DBus"},
{error_code::FAILED_TO_DETECT_LOCATION_CODE_TYPE,
"Failed to detect location code type"},
{error_code::DBUS_FAILURE, "Dbus call failed"},
diff --git a/vpd-manager/include/utility/vpd_specific_utility.hpp b/vpd-manager/include/utility/vpd_specific_utility.hpp
index 30a3b9a..4d36c7b 100644
--- a/vpd-manager/include/utility/vpd_specific_utility.hpp
+++ b/vpd-manager/include/utility/vpd_specific_utility.hpp
@@ -858,15 +858,19 @@
* The API reads the CCIN for a FRU based on its inventory path.
*
* @param[in] i_invObjPath - Inventory path of the FRU.
+ * @param[out] o_errCode - To set error code in case of error.
+ *
* @return CCIN of the FRU on success, empty string otherwise.
*/
-inline std::string getCcinFromDbus(const std::string& i_invObjPath)
+inline std::string getCcinFromDbus(const std::string& i_invObjPath,
+ uint16_t& o_errCode)
{
try
{
if (i_invObjPath.empty())
{
- throw std::runtime_error("Empty EEPROM path, can't read CCIN");
+ o_errCode = error_code::INVALID_INPUT_PARAMETER;
+ return std::string{};
}
const auto& l_retValue = dbusUtility::readDbusProperty(
@@ -874,16 +878,24 @@
constants::kwdCCIN);
auto l_ptrCcin = std::get_if<types::BinaryVector>(&l_retValue);
- if (!l_ptrCcin || (*l_ptrCcin).size() != constants::VALUE_4)
+
+ if (!l_ptrCcin)
{
- throw DbusException("Invalid CCIN read from Dbus");
+ o_errCode = error_code::RECEIVED_INVALID_KWD_TYPE_FROM_DBUS;
+ return std::string{};
+ }
+
+ if ((*l_ptrCcin).size() != constants::VALUE_4)
+ {
+ o_errCode = error_code::INVALID_VALUE_READ_FROM_DBUS;
+ return std::string{};
}
return std::string((*l_ptrCcin).begin(), (*l_ptrCcin).end());
}
catch (const std::exception& l_ex)
{
- logging::logMessage(l_ex.what());
+ o_errCode = error_code::STANDARD_EXCEPTION;
return std::string{};
}
}
diff --git a/vpd-manager/oem-handler/ibm_handler.cpp b/vpd-manager/oem-handler/ibm_handler.cpp
index 99acdc7..766f54c 100644
--- a/vpd-manager/oem-handler/ibm_handler.cpp
+++ b/vpd-manager/oem-handler/ibm_handler.cpp
@@ -218,12 +218,21 @@
// check if the FRU needs CCIN check before updating PN.
if (l_recJson.contains("CCIN"))
{
+ l_errCode = 0;
+
const auto& l_ccinFromDbus =
- vpdSpecificUtility::getCcinFromDbus(l_inventoryPath);
+ vpdSpecificUtility::getCcinFromDbus(l_inventoryPath, l_errCode);
// Not an ideal situation as CCIN can't be empty.
if (l_ccinFromDbus.empty())
{
+ if (l_errCode)
+ {
+ m_logger->logMessage(
+ "Failed to get CCIN value from DBus, error : " +
+ commonUtility::getErrCodeMsg(l_errCode));
+ }
+
o_failedPathList.push_back(l_fruPath);
continue;
}