1 #pragma once 2 3 #include <string> 4 #include <unordered_map> 5 6 namespace vpd 7 { 8 enum error_code 9 { 10 // File exceptions 11 FILE_NOT_FOUND = 2001, /*Just a random value*/ 12 FILE_ACCESS_ERROR, 13 EMPTY_FILE, 14 FILE_SYSTEM_ERROR, 15 16 // JSON exceptions 17 INVALID_JSON, 18 MISSING_FLAG, 19 MISSING_ACTION_TAG, 20 FRU_PATH_NOT_FOUND, 21 JSON_PARSE_ERROR, 22 JSON_MISSING_GPIO_INFO, 23 JSON_MISSING_SERVICE_NAME, 24 REDUNDANT_PATH_NOT_FOUND, 25 ERROR_GETTING_REDUNDANT_PATH, 26 NO_EEPROM_PATH, 27 INVALID_LOCATION_CODE_FORMAT, 28 29 // Generic errors. 30 INVALID_INPUT_PARAMETER, 31 DEVICE_NOT_PRESENT, 32 DEVICE_PRESENCE_UNKNOWN, 33 GPIO_LINE_EXCEPTION, 34 ERROR_PROCESSING_SYSTEM_CMD, 35 STANDARD_EXCEPTION, 36 DBUS_FAILURE, 37 POPEN_FAILED, 38 INVALID_HEXADECIMAL_VALUE_LENGTH, 39 INVALID_HEXADECIMAL_VALUE, 40 INVALID_INVENTORY_PATH, 41 SERVICE_RUNNING, 42 SERVICE_NOT_RUNNING, 43 44 // VPD specific errors 45 UNSUPPORTED_VPD_TYPE, 46 KEYWORD_NOT_FOUND, 47 OUT_OF_BOUND_EXCEPTION, 48 FAILED_TO_DETECT_LOCATION_CODE_TYPE, 49 RECEIVED_INVALID_KWD_TYPE_FROM_DBUS, 50 INVALID_KEYWORD_LENGTH, 51 INVALID_VALUE_READ_FROM_DBUS, 52 RECORD_NOT_FOUND 53 }; 54 55 const std::unordered_map<int, std::string> errorCodeMap = { 56 {error_code::FILE_NOT_FOUND, "File does not exist."}, 57 {error_code::FILE_ACCESS_ERROR, "Failed to access the file."}, 58 {error_code::EMPTY_FILE, "Empty file."}, 59 {error_code::INVALID_JSON, 60 "Either JSON is missing FRU tag or invalid JSON object."}, 61 {error_code::MISSING_FLAG, 62 "JSON is missing the flag to procees for the FRU."}, 63 {error_code::MISSING_ACTION_TAG, 64 "JSON is missing the action tag to be performed for the FRU."}, 65 {error_code::FRU_PATH_NOT_FOUND, "The FRU path is not found in the JSON."}, 66 {error_code::JSON_PARSE_ERROR, "Error while parsing JSON file."}, 67 {error_code::INVALID_INPUT_PARAMETER, 68 "Either one of the input parameter is invalid or empty."}, 69 {error_code::JSON_MISSING_GPIO_INFO, "JSON missing required GPIO info."}, 70 {error_code::JSON_MISSING_SERVICE_NAME, 71 "JSON missing the service name for the FRU"}, 72 {error_code::REDUNDANT_PATH_NOT_FOUND, "No redundant path for the FRU."}, 73 {error_code::ERROR_GETTING_REDUNDANT_PATH, 74 "Error while trying to get redundant path for the FRU"}, 75 {error_code::NO_EEPROM_PATH, "EEPROM path not found."}, 76 {error_code::INVALID_LOCATION_CODE_FORMAT, 77 "Malformed location code format found."}, 78 {error_code::DEVICE_NOT_PRESENT, 79 "Presence pin read successfully but device was absent."}, 80 {error_code::DEVICE_PRESENCE_UNKNOWN, "Exception on presence line GPIO."}, 81 {error_code::GPIO_LINE_EXCEPTION, "There was an exception in GPIO line."}, 82 {error_code::ERROR_PROCESSING_SYSTEM_CMD, 83 "Error while executing system command tag."}, 84 {error_code::KEYWORD_NOT_FOUND, "Keyword not found"}, 85 {error_code::OUT_OF_BOUND_EXCEPTION, "Out of bound error"}, 86 {error_code::UNSUPPORTED_VPD_TYPE, "This VPD type is not supported"}, 87 {error_code::STANDARD_EXCEPTION, "Standard Exception thrown"}, 88 {error_code::FILE_SYSTEM_ERROR, "File system error."}, 89 {error_code::INVALID_KEYWORD_LENGTH, "Invalid keyword length."}, 90 {error_code::INVALID_VALUE_READ_FROM_DBUS, "Invalid value read from DBus"}, 91 {error_code::RECORD_NOT_FOUND, "Record not found."}, 92 {error_code::FAILED_TO_DETECT_LOCATION_CODE_TYPE, 93 "Failed to detect location code type"}, 94 {error_code::DBUS_FAILURE, "Dbus call failed"}, 95 {error_code::RECEIVED_INVALID_KWD_TYPE_FROM_DBUS, 96 "Received invalid keyword data type from DBus."}, 97 {error_code::POPEN_FAILED, "popen failed"}, 98 {error_code::INVALID_HEXADECIMAL_VALUE_LENGTH, 99 "Invalid hexadecimal value length."}, 100 {error_code::INVALID_HEXADECIMAL_VALUE, "Invalid hexadecimal value."}, 101 {error_code::INVALID_INVENTORY_PATH, "Invalid inventory path."}, 102 {error_code::SERVICE_RUNNING, "Service is running"}, 103 {error_code::SERVICE_NOT_RUNNING, "Service is not running"}}; 104 } // namespace vpd 105