Update json_utility APIs with error codes
This commit updates API getVPDOffset and getInventoryObjPathFromJson to
set error codes in case of errors/exceptions. This helps caller of the
APIs to take action based on the error code returned from the API.
Change-Id: Icfe2640ee311d61e83ca302e5199ce4dd1057c8b
Signed-off-by: Rekha Aparna <vrekhaaparna@ibm.com>
diff --git a/vpd-manager/src/backup_restore.cpp b/vpd-manager/src/backup_restore.cpp
index 6c31eac..61d5ba5 100644
--- a/vpd-manager/src/backup_restore.cpp
+++ b/vpd-manager/src/backup_restore.cpp
@@ -162,14 +162,38 @@
return;
}
- const std::string l_srcInvPath =
- jsonUtility::getInventoryObjPathFromJson(m_sysCfgJsonObj, i_srcPath);
- const std::string l_dstInvPath =
- jsonUtility::getInventoryObjPathFromJson(m_sysCfgJsonObj, i_dstPath);
- if (l_srcInvPath.empty() || l_dstInvPath.empty())
+ uint16_t l_errCode = 0;
+ const std::string l_srcInvPath = jsonUtility::getInventoryObjPathFromJson(
+ m_sysCfgJsonObj, i_srcPath, l_errCode);
+
+ if (l_srcInvPath.empty())
{
- logging::logMessage(
- "Couldn't find either source or destination inventory path.");
+ if (l_errCode)
+ {
+ logging::logMessage(
+ "Couldn't find source inventory path. Error : " +
+ vpdSpecificUtility::getErrCodeMsg(l_errCode));
+ return;
+ }
+
+ logging::logMessage("Couldn't find source inventory path.");
+ return;
+ }
+
+ const std::string l_dstInvPath = jsonUtility::getInventoryObjPathFromJson(
+ m_sysCfgJsonObj, i_dstPath, l_errCode);
+
+ if (l_dstInvPath.empty())
+ {
+ if (l_errCode)
+ {
+ logging::logMessage(
+ "Couldn't find destination inventory path. Error : " +
+ vpdSpecificUtility::getErrCodeMsg(l_errCode));
+ return;
+ }
+
+ logging::logMessage("Couldn't find destination inventory path.");
return;
}