blob: 347e704f2a7eb639bcf3bc6eec4f3a553c2c0205 [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
Sunny Srivastava0a5fce12025-04-09 11:09:51 +0530141 /** @brief constructor
142 * @param[in] msg - Information w.r.t. exception.
143 */
144 JsonException(const std::string& msg) : Exception(msg) {}
145
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -0500146 /** @brief Json path getter method.
147 *
148 * @return - Json path
149 */
150 inline std::string getJsonPath() const
151 {
152 return m_jsonPath;
153 }
154
Priyanga Ramasamyf2dbe2e2025-01-30 08:09:47 -0600155 /** @brief Method to get error type
156 *
157 * @return Error type which has to be logged for errors of type
158 * JsonException.
159 */
160 types::ErrorType getErrorType() const
161 {
162 return types::ErrorType::JsonFailure;
163 }
164
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -0500165 private:
166 /** To hold the path of Json that failed*/
167 std::string m_jsonPath;
168
169}; // class JSonException
170
171/** @class GpioException
172 * @brief Custom handler for GPIO exception.
173 *
174 * This class extends Exceptions class and define
175 * type for GPIO related exception in VPD.
176 */
177class GpioException : public Exception
178{
179 public:
180 // deleted methods
181 GpioException() = delete;
182 GpioException(const GpioException&) = delete;
183 GpioException(GpioException&&) = delete;
184 GpioException& operator=(const GpioException&) = delete;
185
186 // default destructor
187 ~GpioException() = default;
188
189 /** @brief constructor
190 * @param[in] msg - string to define exception
191 */
192 explicit GpioException(const std::string& msg) : Exception(msg) {}
Priyanga Ramasamyf2dbe2e2025-01-30 08:09:47 -0600193
194 /** @brief Method to get error type
195 *
196 * @return Error type which has to be logged for errors of type
197 * GpioException.
198 */
199 types::ErrorType getErrorType() const
200 {
201 return types::ErrorType::GpioError;
202 }
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -0500203};
204
Sunny Srivastavaa88a2982025-01-23 12:03:21 +0530205/** @class DbusException
206 * @brief Custom handler for Dbus exception.
207 *
208 * This class extends Exceptions class and define
209 * type for DBus related exception in VPD.
210 */
211class DbusException : public Exception
212{
213 public:
214 // deleted methods
215 DbusException() = delete;
216 DbusException(const DbusException&) = delete;
217 DbusException(DbusException&&) = delete;
218 DbusException& operator=(const DbusException&) = delete;
219
220 // default destructor
221 ~DbusException() = default;
222
223 /** @brief constructor
224 * @param[in] msg - string to define exception
225 */
226 explicit DbusException(const std::string& msg) : Exception(msg) {}
Priyanga Ramasamyf2dbe2e2025-01-30 08:09:47 -0600227
228 /** @brief Method to get error type
229 *
230 * @return Error type which has to be logged for errors of type
231 * DbusException.
232 */
233 types::ErrorType getErrorType() const
234 {
235 return types::ErrorType::DbusFailure;
236 }
Sunny Srivastavaa88a2982025-01-23 12:03:21 +0530237};
238
239/** @class FirmwareException
240 * @brief Custom handler for firmware exception.
241 *
242 * This class extends Exceptions class and define
243 * type for generic firmware related exception in VPD.
244 */
245class FirmwareException : public Exception
246{
247 public:
248 // deleted methods
249 FirmwareException() = delete;
250 FirmwareException(const FirmwareException&) = delete;
251 FirmwareException(FirmwareException&&) = delete;
252 FirmwareException& operator=(const FirmwareException&) = delete;
253
254 // default destructor
255 ~FirmwareException() = default;
256
257 /** @brief constructor
258 * @param[in] msg - string to define exception
259 */
260 explicit FirmwareException(const std::string& msg) : Exception(msg) {}
Priyanga Ramasamyf2dbe2e2025-01-30 08:09:47 -0600261
262 /** @brief Method to get error type
263 *
264 * @return Error type which has to be logged for errors of type
265 * FirmwareException.
266 */
267 types::ErrorType getErrorType() const
268 {
269 return types::ErrorType::InternalFailure;
270 }
Sunny Srivastavaa88a2982025-01-23 12:03:21 +0530271};
272
273/** @class EepromException
274 * @brief Custom handler for EEPROM exception.
275 *
276 * This class extends Exceptions class and define
277 * type for EEPROM related exception in VPD.
278 */
279class EepromException : public Exception
280{
281 public:
282 // deleted methods
283 EepromException() = delete;
284 EepromException(const EepromException&) = delete;
285 EepromException(EepromException&&) = delete;
286 EepromException& operator=(const EepromException&) = delete;
287
288 // default destructor
289 ~EepromException() = default;
290
291 /** @brief constructor
292 * @param[in] msg - string to define exception
293 */
294 explicit EepromException(const std::string& msg) : Exception(msg) {}
Priyanga Ramasamyf2dbe2e2025-01-30 08:09:47 -0600295
296 /** @brief Method to get error type
297 *
298 * @return Error type which has to be logged for errors of type
299 * EepromException.
300 */
301 types::ErrorType getErrorType() const
302 {
303 return types::ErrorType::InvalidEeprom;
304 }
Sunny Srivastavaa88a2982025-01-23 12:03:21 +0530305};
306
Sunny Srivastavafa5e4d32023-03-12 11:59:49 -0500307} // namespace vpd