Define map linking error codes to error messages
This commit defines a map that associate error code with human readable
error messages, allows direct lookup and eliminates the need for
conditional checks. Improves code clarity and maintainability.
Change-Id: I47fe8ef7e208d9a2917758e78a5222577b218405
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 737d4e5..42b010a 100644
--- a/vpd-manager/include/error_codes.hpp
+++ b/vpd-manager/include/error_codes.hpp
@@ -1,5 +1,8 @@
#pragma once
+#include <string>
+#include <unordered_map>
+
namespace vpd
{
namespace error_code
@@ -17,5 +20,17 @@
// Generic errors.
static constexpr auto INVALID_INPUT_PARAMATER = 3001;
+
+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,
+ "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."},
+ {INVALID_INPUT_PARAMATER,
+ "Either one of the input parameter is invalid or empty."}};
} // namespace error_code
} // namespace vpd