1 /** 2 * Copyright © 2020 IBM Corporation 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #pragma once 17 18 #include <exception> 19 #include <string> 20 21 namespace phosphor::power::regulators 22 { 23 24 /** 25 * @class WriteVerificationError 26 * 27 * An error that occurred when performing a read after a write to ensure the 28 * write was successful. 29 * 30 * This exception is thrown when the value read is different than the value 31 * written. This is also known as a readback error. 32 */ 33 class WriteVerificationError : public std::exception 34 { 35 public: 36 // Specify which compiler-generated methods we want 37 WriteVerificationError() = delete; 38 WriteVerificationError(const WriteVerificationError&) = default; 39 WriteVerificationError(WriteVerificationError&&) = default; 40 WriteVerificationError& operator=(const WriteVerificationError&) = default; 41 WriteVerificationError& operator=(WriteVerificationError&&) = default; 42 virtual ~WriteVerificationError() = default; 43 44 /** 45 * Constructor. 46 * 47 * @param error error message 48 * @param deviceID unique ID of the device where error occurred 49 * @param inventoryPath inventory path of the device where error occurred 50 */ 51 explicit WriteVerificationError(const std::string& error, 52 const std::string& deviceID, 53 const std::string& inventoryPath) : 54 error{"WriteVerificationError: " + error}, 55 deviceID{deviceID}, inventoryPath{inventoryPath} 56 { 57 } 58 59 /** 60 * Returns the unique ID of the device where the error occurred. 61 * 62 * @return device ID 63 */ 64 const std::string& getDeviceID() const 65 { 66 return deviceID; 67 } 68 69 /** 70 * Returns the inventory path of the device where the error occurred. 71 * 72 * @return inventory path 73 */ 74 const std::string& getInventoryPath() const 75 { 76 return inventoryPath; 77 } 78 79 /** 80 * Returns the description of this error. 81 * 82 * @return error description 83 */ 84 const char* what() const noexcept override 85 { 86 return error.c_str(); 87 } 88 89 private: 90 /** 91 * Error message. 92 */ 93 const std::string error{}; 94 95 /** 96 * Unique ID of the device where the error occurred. 97 */ 98 const std::string deviceID{}; 99 100 /** 101 * Inventory path of the device where the error occurred. 102 */ 103 const std::string inventoryPath{}; 104 }; 105 106 } // namespace phosphor::power::regulators 107