Defining error codes as enum
The error codes has been moved under enum because of following benefit.
As the number against error codes were not specifying anything. Overhead
of maintaining unique number for each error code goes away.
Change-Id: Id2133c85306c7b65bb3a0ac1d622dda813f2256b
Signed-off-by: Sunny Srivastava <sunnsr25@in.ibm.com>
diff --git a/vpd-manager/include/error_codes.hpp b/vpd-manager/include/error_codes.hpp
index 204b96a..7ba6a5c 100644
--- a/vpd-manager/include/error_codes.hpp
+++ b/vpd-manager/include/error_codes.hpp
@@ -5,43 +5,45 @@
namespace vpd
{
-namespace error_code
+enum error_code
{
-// File exceptions
-static constexpr auto FILE_NOT_FOUND = 1001;
-static constexpr auto FILE_ACCESS_ERROR = 1002;
-static constexpr auto EMPTY_FILE = 1003;
+ // File exceptions
+ FILE_NOT_FOUND = 2001, /*Just a random value*/
+ FILE_ACCESS_ERROR,
+ EMPTY_FILE,
-// JSON exceptions
-static constexpr auto INVALID_JSON = 2001;
-static constexpr auto MISSING_FLAG = 2002;
-static constexpr auto MISSING_ACTION_TAG = 2003;
-static constexpr auto FRU_PATH_NOT_FOUND = 2004;
-static constexpr auto JSON_PARSE_ERROR = 2005;
-static constexpr auto JSON_MISSING_GPIO_INFO = 2006;
+ // JSON exceptions
+ INVALID_JSON,
+ MISSING_FLAG,
+ MISSING_ACTION_TAG,
+ FRU_PATH_NOT_FOUND,
+ JSON_PARSE_ERROR,
+ JSON_MISSING_GPIO_INFO,
-// Generic errors.
-static constexpr auto INVALID_INPUT_PARAMETER = 3001;
-static constexpr auto DEVICE_NOT_PRESENT = 2006;
-static constexpr auto DEVICE_PRESENCE_UNKNOWN = 2007;
-static constexpr auto GPIO_LINE_EXCEPTION = 2008;
+ // Generic errors.
+ INVALID_INPUT_PARAMETER,
+ DEVICE_NOT_PRESENT,
+ DEVICE_PRESENCE_UNKNOWN,
+ GPIO_LINE_EXCEPTION
+};
const std::unordered_map<int, std::string> errorCodeMap = {
- {FILE_NOT_FOUND, "File does not exist."},
- {FILE_ACCESS_ERROR, "Failed to access the file."},
- {EMPTY_FILE, "Empty file."},
- {INVALID_JSON, "Either JSON is missing FRU tag or invalid JSON object."},
- {MISSING_FLAG, "JSON is missing the flag to procees for the FRU."},
- {MISSING_ACTION_TAG,
+ {error_code::FILE_NOT_FOUND, "File does not exist."},
+ {error_code::FILE_ACCESS_ERROR, "Failed to access the file."},
+ {error_code::EMPTY_FILE, "Empty file."},
+ {error_code::INVALID_JSON,
+ "Either JSON is missing FRU tag or invalid JSON object."},
+ {error_code::MISSING_FLAG,
+ "JSON is missing the flag to procees for the FRU."},
+ {error_code::MISSING_ACTION_TAG,
"JSON is missing the action tag to be performed for the FRU."},
- {FRU_PATH_NOT_FOUND, "The FRU path is not found in the JSON."},
- {JSON_PARSE_ERROR, "Error while parsing JSON file."},
- {INVALID_INPUT_PARAMETER,
+ {error_code::FRU_PATH_NOT_FOUND, "The FRU path is not found in the JSON."},
+ {error_code::JSON_PARSE_ERROR, "Error while parsing JSON file."},
+ {error_code::INVALID_INPUT_PARAMETER,
"Either one of the input parameter is invalid or empty."},
- {JSON_MISSING_GPIO_INFO, "JSON missing required GPIO info."},
- {DEVICE_NOT_PRESENT,
+ {error_code::JSON_MISSING_GPIO_INFO, "JSON missing required GPIO info."},
+ {error_code::DEVICE_NOT_PRESENT,
"Presence pin read successfully but device was absent."},
- {DEVICE_PRESENCE_UNKNOWN, "Exception on presence line GPIO."},
- {GPIO_LINE_EXCEPTION, "There was an exception in GPIO line."}};
-} // namespace error_code
+ {error_code::DEVICE_PRESENCE_UNKNOWN, "Exception on presence line GPIO."},
+ {error_code::GPIO_LINE_EXCEPTION, "There was an exception in GPIO line."}};
} // namespace vpd
diff --git a/vpd-manager/include/utility/vpd_specific_utility.hpp b/vpd-manager/include/utility/vpd_specific_utility.hpp
index e366963..d72b7f3 100644
--- a/vpd-manager/include/utility/vpd_specific_utility.hpp
+++ b/vpd-manager/include/utility/vpd_specific_utility.hpp
@@ -1125,10 +1125,9 @@
*/
inline std::string getErrCodeMsg(const uint16_t& i_errCode)
{
- if (error_code::errorCodeMap.find(i_errCode) !=
- error_code::errorCodeMap.end())
+ if (errorCodeMap.find(i_errCode) != errorCodeMap.end())
{
- return error_code::errorCodeMap.at(i_errCode);
+ return errorCodeMap.at(i_errCode);
}
return std::string{};