blob: 7109453790210e5a9eb87b9dc916c174af7e5372 [file] [log] [blame]
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -05001#pragma once
2
Priyanga Ramasamyf2dbe2e2025-01-30 08:09:47 -06003#include "types.hpp"
4
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -05005#include <stdexcept>
6
7namespace vpd
8{
9/** @class Exception
10 * @brief This class inherits std::runtime_error and overrrides "what" method
11 * to return the description of exception.
12 * This class also works as base class for custom exception classes for
13 * VPD repository.
14 */
15class Exception : public std::runtime_error
16{
17 public:
18 // deleted methods
19 Exception() = delete;
20 Exception(const Exception&) = delete;
21 Exception(Exception&&) = delete;
22 Exception& operator=(const Exception&) = delete;
23
24 // default destructor
25 ~Exception() = default;
26
27 /** @brief constructor
28 *
29 * @param[in] msg - Information w.r.t exception.
30 */
31 explicit Exception(const std::string& msg) :
32 std::runtime_error(msg), m_errMsg(msg)
33 {}
34
35 /** @brief inline method to return exception string.
36 *
37 * This is overridden method of std::runtime class.
38 */
39 inline const char* what() const noexcept override
40 {
41 return m_errMsg.c_str();
42 }
43
Priyanga Ramasamyf2dbe2e2025-01-30 08:09:47 -060044 // TODO: Create getErrorType api by defining VPD default error type
45
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -050046 private:
47 /** @brief string to hold the reason of exception */
48 std::string m_errMsg;
49
50}; // class Exception
51
52/** @class EccException
53 *
54 * @brief This class extends Exceptions class and define type for ECC related
55 * exception in VPD.
56 */
57class EccException : public Exception
58{
59 public:
60 // deleted methods
61 EccException() = delete;
62 EccException(const EccException&) = delete;
63 EccException(EccException&&) = delete;
64 EccException& operator=(const EccException&) = delete;
65
66 // default destructor
67 ~EccException() = default;
68
69 /** @brief constructor
70 *
71 * @param[in] msg - Information w.r.t exception.
72 */
73 explicit EccException(const std::string& msg) : Exception(msg) {}
74
Priyanga Ramasamyf2dbe2e2025-01-30 08:09:47 -060075 /** @brief Method to get error type
76 *
77 * @return Error type which has to be logged for errors of type
78 * EccException.
79 */
80 types::ErrorType getErrorType() const
81 {
82 return types::ErrorType::EccCheckFailed;
83 }
84
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -050085}; // class EccException
86
87/** @class DataException
88 *
89 * @brief This class extends Exceptions class and define type for data related
90 * exception in VPD
91 */
92class DataException : public Exception
93{
94 public:
95 // deleted methods
96 DataException() = delete;
97 DataException(const DataException&) = delete;
98 DataException(DataException&&) = delete;
99 DataException& operator=(const DataException&) = delete;
100
101 // default destructor
102 ~DataException() = default;
103
104 /** @brief constructor
105 *
106 * @param[in] msg - string to define exception
107 */
108 explicit DataException(const std::string& msg) : Exception(msg) {}
109
Priyanga Ramasamyf2dbe2e2025-01-30 08:09:47 -0600110 /** @brief Method to get error type
111 *
112 * @return Error type which has to be logged for errors of type
113 * DataException.
114 */
115 types::ErrorType getErrorType() const
116 {
117 return types::ErrorType::InvalidVpdMessage;
118 }
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -0500119}; // class DataException
120
121class JsonException : public Exception
122{
123 public:
124 // deleted methods
125 JsonException() = delete;
126 JsonException(const JsonException&) = delete;
127 JsonException(JsonException&&) = delete;
128 JsonException& operator=(const JsonException&) = delete;
129
130 // default destructor
131 ~JsonException() = default;
132
133 /** @brief constructor
134 * @param[in] msg - Information w.r.t. exception.
135 * @param[in] path - Json path
136 */
137 JsonException(const std::string& msg, const std::string& path) :
138 Exception(msg), m_jsonPath(path)
139 {}
140
141 /** @brief Json path getter method.
142 *
143 * @return - Json path
144 */
145 inline std::string getJsonPath() const
146 {
147 return m_jsonPath;
148 }
149
Priyanga Ramasamyf2dbe2e2025-01-30 08:09:47 -0600150 /** @brief Method to get error type
151 *
152 * @return Error type which has to be logged for errors of type
153 * JsonException.
154 */
155 types::ErrorType getErrorType() const
156 {
157 return types::ErrorType::JsonFailure;
158 }
159
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -0500160 private:
161 /** To hold the path of Json that failed*/
162 std::string m_jsonPath;
163
164}; // class JSonException
165
166/** @class GpioException
167 * @brief Custom handler for GPIO exception.
168 *
169 * This class extends Exceptions class and define
170 * type for GPIO related exception in VPD.
171 */
172class GpioException : public Exception
173{
174 public:
175 // deleted methods
176 GpioException() = delete;
177 GpioException(const GpioException&) = delete;
178 GpioException(GpioException&&) = delete;
179 GpioException& operator=(const GpioException&) = delete;
180
181 // default destructor
182 ~GpioException() = default;
183
184 /** @brief constructor
185 * @param[in] msg - string to define exception
186 */
187 explicit GpioException(const std::string& msg) : Exception(msg) {}
Priyanga Ramasamyf2dbe2e2025-01-30 08:09:47 -0600188
189 /** @brief Method to get error type
190 *
191 * @return Error type which has to be logged for errors of type
192 * GpioException.
193 */
194 types::ErrorType getErrorType() const
195 {
196 return types::ErrorType::GpioError;
197 }
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -0500198};
199
Sunny Srivastavaa88a2982025-01-23 12:03:21 +0530200/** @class DbusException
201 * @brief Custom handler for Dbus exception.
202 *
203 * This class extends Exceptions class and define
204 * type for DBus related exception in VPD.
205 */
206class DbusException : public Exception
207{
208 public:
209 // deleted methods
210 DbusException() = delete;
211 DbusException(const DbusException&) = delete;
212 DbusException(DbusException&&) = delete;
213 DbusException& operator=(const DbusException&) = delete;
214
215 // default destructor
216 ~DbusException() = default;
217
218 /** @brief constructor
219 * @param[in] msg - string to define exception
220 */
221 explicit DbusException(const std::string& msg) : Exception(msg) {}
Priyanga Ramasamyf2dbe2e2025-01-30 08:09:47 -0600222
223 /** @brief Method to get error type
224 *
225 * @return Error type which has to be logged for errors of type
226 * DbusException.
227 */
228 types::ErrorType getErrorType() const
229 {
230 return types::ErrorType::DbusFailure;
231 }
Sunny Srivastavaa88a2982025-01-23 12:03:21 +0530232};
233
234/** @class FirmwareException
235 * @brief Custom handler for firmware exception.
236 *
237 * This class extends Exceptions class and define
238 * type for generic firmware related exception in VPD.
239 */
240class FirmwareException : public Exception
241{
242 public:
243 // deleted methods
244 FirmwareException() = delete;
245 FirmwareException(const FirmwareException&) = delete;
246 FirmwareException(FirmwareException&&) = delete;
247 FirmwareException& operator=(const FirmwareException&) = delete;
248
249 // default destructor
250 ~FirmwareException() = default;
251
252 /** @brief constructor
253 * @param[in] msg - string to define exception
254 */
255 explicit FirmwareException(const std::string& msg) : Exception(msg) {}
Priyanga Ramasamyf2dbe2e2025-01-30 08:09:47 -0600256
257 /** @brief Method to get error type
258 *
259 * @return Error type which has to be logged for errors of type
260 * FirmwareException.
261 */
262 types::ErrorType getErrorType() const
263 {
264 return types::ErrorType::InternalFailure;
265 }
Sunny Srivastavaa88a2982025-01-23 12:03:21 +0530266};
267
268/** @class EepromException
269 * @brief Custom handler for EEPROM exception.
270 *
271 * This class extends Exceptions class and define
272 * type for EEPROM related exception in VPD.
273 */
274class EepromException : public Exception
275{
276 public:
277 // deleted methods
278 EepromException() = delete;
279 EepromException(const EepromException&) = delete;
280 EepromException(EepromException&&) = delete;
281 EepromException& operator=(const EepromException&) = delete;
282
283 // default destructor
284 ~EepromException() = default;
285
286 /** @brief constructor
287 * @param[in] msg - string to define exception
288 */
289 explicit EepromException(const std::string& msg) : Exception(msg) {}
Priyanga Ramasamyf2dbe2e2025-01-30 08:09:47 -0600290
291 /** @brief Method to get error type
292 *
293 * @return Error type which has to be logged for errors of type
294 * EepromException.
295 */
296 types::ErrorType getErrorType() const
297 {
298 return types::ErrorType::InvalidEeprom;
299 }
Sunny Srivastavaa88a2982025-01-23 12:03:21 +0530300};
301
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -0500302} // namespace vpd