xref: /openbmc/openpower-vpd-parser/vpd-manager/src/event_logger.cpp (revision c6159a29119d5e08476ed85eaf1cf47ebf9bebdb)
1 #include "config.h"
2 
3 #include "event_logger.hpp"
4 
5 #include "exceptions.hpp"
6 #include "logger.hpp"
7 
8 #include <systemd/sd-bus.h>
9 
10 #include <utility/common_utility.hpp>
11 #include <utility/json_utility.hpp>
12 #include <utility/vpd_specific_utility.hpp>
13 
14 #include <filesystem>
15 
16 namespace vpd
17 {
18 const std::unordered_map<types::SeverityType, std::string>
19     EventLogger::m_severityMap = {
20         {types::SeverityType::Notice,
21          "xyz.openbmc_project.Logging.Entry.Level.Notice"},
22         {types::SeverityType::Informational,
23          "xyz.openbmc_project.Logging.Entry.Level.Informational"},
24         {types::SeverityType::Debug,
25          "xyz.openbmc_project.Logging.Entry.Level.Debug"},
26         {types::SeverityType::Warning,
27          "xyz.openbmc_project.Logging.Entry.Level.Warning"},
28         {types::SeverityType::Critical,
29          "xyz.openbmc_project.Logging.Entry.Level.Critical"},
30         {types::SeverityType::Emergency,
31          "xyz.openbmc_project.Logging.Entry.Level.Emergency"},
32         {types::SeverityType::Alert,
33          "xyz.openbmc_project.Logging.Entry.Level.Alert"},
34         {types::SeverityType::Error,
35          "xyz.openbmc_project.Logging.Entry.Level.Error"}};
36 
37 const std::unordered_map<types::ErrorType, std::string>
38     EventLogger::m_errorMsgMap = {
39         {types::ErrorType::DefaultValue, "com.ibm.VPD.Error.DefaultValue"},
40         {types::ErrorType::UndefinedError, "com.ibm.VPD.Error.UndefinedError"},
41         {types::ErrorType::InvalidVpdMessage, "com.ibm.VPD.Error.InvalidVPD"},
42         {types::ErrorType::VpdMismatch, "com.ibm.VPD.Error.Mismatch"},
43         {types::ErrorType::InvalidEeprom,
44          "com.ibm.VPD.Error.InvalidEepromPath"},
45         {types::ErrorType::EccCheckFailed, "com.ibm.VPD.Error.EccCheckFailed"},
46         {types::ErrorType::JsonFailure, "com.ibm.VPD.Error.InvalidJson"},
47         {types::ErrorType::DbusFailure, "com.ibm.VPD.Error.DbusFailure"},
48         {types::ErrorType::InvalidSystem,
49          "com.ibm.VPD.Error.UnknownSystemType"},
50         {types::ErrorType::EssentialFru,
51          "com.ibm.VPD.Error.RequiredFRUMissing"},
52         {types::ErrorType::GpioError, "com.ibm.VPD.Error.GPIOError"},
53         {types::ErrorType::InternalFailure,
54          "xyz.openbmc_project.Common.Error.InternalFailure"},
55         {types::ErrorType::FruMissing, "com.ibm.VPD.Error.RequiredFRUMissing"},
56         {types::ErrorType::SystemTypeMismatch,
57          "com.ibm.VPD.Error.SystemTypeMismatch"},
58         {types::ErrorType::UnknownSystemSettings,
59          "com.ibm.VPD.Error.UnknownSystemSettings"},
60         {types::ErrorType::FirmwareError, "com.ibm.VPD.Error.FirmwareError"},
61         {types::ErrorType::VpdParseError, "com.ibm.VPD.Error.VPDParseError"}};
62 
63 const std::unordered_map<types::CalloutPriority, std::string>
64     EventLogger::m_priorityMap = {
65         {types::CalloutPriority::High, "H"},
66         {types::CalloutPriority::Medium, "M"},
67         {types::CalloutPriority::MediumGroupA, "A"},
68         {types::CalloutPriority::MediumGroupB, "B"},
69         {types::CalloutPriority::MediumGroupC, "C"},
70         {types::CalloutPriority::Low, "L"}};
71 
createAsyncPelWithInventoryCallout(const types::ErrorType & i_errorType,const types::SeverityType & i_severity,const std::vector<types::InventoryCalloutData> & i_callouts,const std::string & i_fileName,const std::string & i_funcName,const uint8_t i_internalRc,const std::string & i_description,const std::optional<std::string> i_userData1,const std::optional<std::string> i_userData2,const std::optional<std::string> i_symFru,const std::optional<std::string> i_procedure)72 void EventLogger::createAsyncPelWithInventoryCallout(
73     const types::ErrorType& i_errorType, const types::SeverityType& i_severity,
74     const std::vector<types::InventoryCalloutData>& i_callouts,
75     const std::string& i_fileName, const std::string& i_funcName,
76     const uint8_t i_internalRc, const std::string& i_description,
77     const std::optional<std::string> i_userData1,
78     const std::optional<std::string> i_userData2,
79     const std::optional<std::string> i_symFru,
80     const std::optional<std::string> i_procedure)
81 {
82     (void)i_symFru;
83     (void)i_procedure;
84 
85     try
86     {
87         if (i_callouts.empty())
88         {
89             logging::logMessage("Callout information is missing to create PEL");
90             // TODO: Revisit this instead of simpley returning.
91             return;
92         }
93 
94         if (m_errorMsgMap.find(i_errorType) == m_errorMsgMap.end())
95         {
96             throw std::runtime_error(
97                 "Error type not found in the error message map to create PEL");
98             // TODO: Need to handle, instead of throwing exception. Create
99             // default message in message_registry.json.
100         }
101 
102         const std::string& l_message = m_errorMsgMap.at(i_errorType);
103 
104         const std::string& l_severity =
105             (m_severityMap.find(i_severity) != m_severityMap.end()
106                  ? m_severityMap.at(i_severity)
107                  : m_severityMap.at(types::SeverityType::Informational));
108 
109         std::string l_description =
110             (!i_description.empty() ? i_description : "VPD generic error");
111 
112         std::string l_userData1 = (i_userData1) ? (*i_userData1) : "";
113 
114         std::string l_userData2 = (i_userData2) ? (*i_userData2) : "";
115 
116         const types::InventoryCalloutData& l_invCallout = i_callouts[0];
117         // TODO: Need to handle multiple inventory path callout's, when multiple
118         // callout's is supported by "Logging" service.
119 
120         const types::CalloutPriority& l_priorityEnum = get<1>(l_invCallout);
121 
122         const std::string& l_priority =
123             (m_priorityMap.find(l_priorityEnum) != m_priorityMap.end()
124                  ? m_priorityMap.at(l_priorityEnum)
125                  : m_priorityMap.at(types::CalloutPriority::Low));
126 
127         sd_bus* l_sdBus = nullptr;
128         sd_bus_default(&l_sdBus);
129 
130         const uint8_t l_additionalDataCount = 8;
131         auto l_rc = sd_bus_call_method_async(
132             l_sdBus, NULL, constants::eventLoggingServiceName,
133             constants::eventLoggingObjectPath, constants::eventLoggingInterface,
134             "Create", NULL, NULL, "ssa{ss}", l_message.c_str(),
135             l_severity.c_str(), l_additionalDataCount, "FileName",
136             i_fileName.c_str(), "FunctionName", i_funcName.c_str(),
137             "InternalRc", std::to_string(i_internalRc).c_str(), "DESCRIPTION",
138             l_description.c_str(), "UserData1", l_userData1.c_str(),
139             "UserData2", l_userData2.c_str(), "CALLOUT_INVENTORY_PATH",
140             get<0>(l_invCallout).c_str(), "CALLOUT_PRIORITY",
141             l_priority.c_str());
142 
143         if (l_rc < 0)
144         {
145             logging::logMessage(
146                 "Error calling sd_bus_call_method_async, Message = " +
147                 std::string(strerror(-l_rc)));
148         }
149     }
150     catch (const std::exception& l_ex)
151     {
152         logging::logMessage(
153             "Create PEL failed with error: " + std::string(l_ex.what()));
154     }
155 }
156 
createAsyncPelWithI2cDeviceCallout(const types::ErrorType i_errorType,const types::SeverityType i_severity,const std::vector<types::DeviceCalloutData> & i_callouts,const std::string & i_fileName,const std::string & i_funcName,const uint8_t i_internalRc,const std::optional<std::pair<std::string,std::string>> i_userData1,const std::optional<std::pair<std::string,std::string>> i_userData2)157 void EventLogger::createAsyncPelWithI2cDeviceCallout(
158     const types::ErrorType i_errorType, const types::SeverityType i_severity,
159     const std::vector<types::DeviceCalloutData>& i_callouts,
160     const std::string& i_fileName, const std::string& i_funcName,
161     const uint8_t i_internalRc,
162     const std::optional<std::pair<std::string, std::string>> i_userData1,
163     const std::optional<std::pair<std::string, std::string>> i_userData2)
164 {
165     // TODO, implementation needs to be added.
166     (void)i_errorType;
167     (void)i_severity;
168     (void)i_callouts;
169     (void)i_fileName;
170     (void)i_funcName;
171     (void)i_internalRc;
172     (void)i_userData1;
173     (void)i_userData2;
174 }
175 
createAsyncPelWithI2cBusCallout(const types::ErrorType i_errorType,const types::SeverityType i_severity,const std::vector<types::I2cBusCalloutData> & i_callouts,const std::string & i_fileName,const std::string & i_funcName,const uint8_t i_internalRc,const std::optional<std::pair<std::string,std::string>> i_userData1,const std::optional<std::pair<std::string,std::string>> i_userData2)176 void EventLogger::createAsyncPelWithI2cBusCallout(
177     const types::ErrorType i_errorType, const types::SeverityType i_severity,
178     const std::vector<types::I2cBusCalloutData>& i_callouts,
179     const std::string& i_fileName, const std::string& i_funcName,
180     const uint8_t i_internalRc,
181     const std::optional<std::pair<std::string, std::string>> i_userData1,
182     const std::optional<std::pair<std::string, std::string>> i_userData2)
183 {
184     // TODO, implementation needs to be added.
185     (void)i_errorType;
186     (void)i_severity;
187     (void)i_callouts;
188     (void)i_fileName;
189     (void)i_funcName;
190     (void)i_internalRc;
191     (void)i_userData1;
192     (void)i_userData2;
193 }
194 
createAsyncPel(const types::ErrorType & i_errorType,const types::SeverityType & i_severity,const std::string & i_fileName,const std::string & i_funcName,const uint8_t i_internalRc,const std::string & i_description,const std::optional<std::string> i_userData1,const std::optional<std::string> i_userData2,const std::optional<std::string> i_symFru,const std::optional<std::string> i_procedure)195 void EventLogger::createAsyncPel(
196     const types::ErrorType& i_errorType, const types::SeverityType& i_severity,
197     const std::string& i_fileName, const std::string& i_funcName,
198     const uint8_t i_internalRc, const std::string& i_description,
199     const std::optional<std::string> i_userData1,
200     const std::optional<std::string> i_userData2,
201     const std::optional<std::string> i_symFru,
202     const std::optional<std::string> i_procedure)
203 {
204     (void)i_symFru;
205     (void)i_procedure;
206     try
207     {
208         if (m_errorMsgMap.find(i_errorType) == m_errorMsgMap.end())
209         {
210             throw std::runtime_error("Unsupported error type received");
211             // TODO: Need to handle, instead of throwing an exception.
212         }
213 
214         const std::string& l_message = m_errorMsgMap.at(i_errorType);
215 
216         const std::string& l_severity =
217             (m_severityMap.find(i_severity) != m_severityMap.end()
218                  ? m_severityMap.at(i_severity)
219                  : m_severityMap.at(types::SeverityType::Informational));
220 
221         const std::string l_description =
222             ((!i_description.empty() ? i_description : "VPD generic error"));
223 
224         const std::string l_userData1 = ((i_userData1) ? (*i_userData1) : "");
225 
226         const std::string l_userData2 = ((i_userData2) ? (*i_userData2) : "");
227 
228         sd_bus* l_sdBus = nullptr;
229         sd_bus_default(&l_sdBus);
230 
231         // VALUE_6 represents the additional data pair count passing to create
232         // PEL. If there any change in additional data, we need to pass the
233         // correct number.
234         auto l_rc = sd_bus_call_method_async(
235             l_sdBus, NULL, constants::eventLoggingServiceName,
236             constants::eventLoggingObjectPath, constants::eventLoggingInterface,
237             "Create", NULL, NULL, "ssa{ss}", l_message.c_str(),
238             l_severity.c_str(), constants::VALUE_6, "FileName",
239             i_fileName.c_str(), "FunctionName", i_funcName.c_str(),
240             "InternalRc", std::to_string(i_internalRc).c_str(), "DESCRIPTION",
241             l_description.c_str(), "UserData1", l_userData1.c_str(),
242             "UserData2", l_userData2.c_str());
243 
244         if (l_rc < 0)
245         {
246             logging::logMessage(
247                 "Error calling sd_bus_call_method_async, Message = " +
248                 std::string(strerror(-l_rc)));
249         }
250     }
251     catch (const sdbusplus::exception::SdBusError& l_ex)
252     {
253         logging::logMessage("Async PEL creation failed with an error: " +
254                             std::string(l_ex.what()));
255     }
256 }
257 
createSyncPel(const types::ErrorType & i_errorType,const types::SeverityType & i_severity,const std::string & i_fileName,const std::string & i_funcName,const uint8_t i_internalRc,const std::string & i_description,const std::optional<std::string> i_userData1,const std::optional<std::string> i_userData2,const std::optional<std::string> i_symFru,const std::optional<std::string> i_procedure)258 void EventLogger::createSyncPel(
259     const types::ErrorType& i_errorType, const types::SeverityType& i_severity,
260     const std::string& i_fileName, const std::string& i_funcName,
261     const uint8_t i_internalRc, const std::string& i_description,
262     const std::optional<std::string> i_userData1,
263     const std::optional<std::string> i_userData2,
264     const std::optional<std::string> i_symFru,
265     const std::optional<std::string> i_procedure)
266 {
267     (void)i_symFru;
268     (void)i_procedure;
269     try
270     {
271         if (m_errorMsgMap.find(i_errorType) == m_errorMsgMap.end())
272         {
273             throw std::runtime_error("Unsupported error type received");
274             // TODO: Need to handle, instead of throwing an exception.
275         }
276 
277         const std::string& l_message = m_errorMsgMap.at(i_errorType);
278 
279         const std::string& l_severity =
280             (m_severityMap.find(i_severity) != m_severityMap.end()
281                  ? m_severityMap.at(i_severity)
282                  : m_severityMap.at(types::SeverityType::Informational));
283 
284         const std::string l_description =
285             ((!i_description.empty() ? i_description : "VPD generic error"));
286 
287         const std::string l_userData1 = ((i_userData1) ? (*i_userData1) : "");
288 
289         const std::string l_userData2 = ((i_userData2) ? (*i_userData2) : "");
290 
291         std::map<std::string, std::string> l_additionalData{
292             {"FileName", i_fileName},
293             {"FunctionName", i_funcName},
294             {"DESCRIPTION", l_description},
295             {"InteranlRc", std::to_string(i_internalRc)},
296             {"UserData1", l_userData1.c_str()},
297             {"UserData2", l_userData2.c_str()}};
298 
299         auto l_bus = sdbusplus::bus::new_default();
300         auto l_method =
301             l_bus.new_method_call(constants::eventLoggingServiceName,
302                                   constants::eventLoggingObjectPath,
303                                   constants::eventLoggingInterface, "Create");
304         l_method.append(l_message, l_severity, l_additionalData);
305         l_bus.call(l_method);
306     }
307     catch (const sdbusplus::exception::SdBusError& l_ex)
308     {
309         logging::logMessage("Sync PEL creation failed with an error: " +
310                             std::string(l_ex.what()));
311     }
312 }
313 
createSyncPelWithInvCallOut(const types::ErrorType & i_errorType,const types::SeverityType & i_severity,const std::string & i_fileName,const std::string & i_funcName,const uint8_t i_internalRc,const std::string & i_description,const std::vector<types::InventoryCalloutData> & i_callouts,const std::optional<std::string> i_userData1,const std::optional<std::string> i_userData2,const std::optional<std::string> i_symFru,const std::optional<std::string> i_procedure)314 void EventLogger::createSyncPelWithInvCallOut(
315     const types::ErrorType& i_errorType, const types::SeverityType& i_severity,
316     const std::string& i_fileName, const std::string& i_funcName,
317     const uint8_t i_internalRc, const std::string& i_description,
318     const std::vector<types::InventoryCalloutData>& i_callouts,
319     const std::optional<std::string> i_userData1,
320     const std::optional<std::string> i_userData2,
321     [[maybe_unused]] const std::optional<std::string> i_symFru,
322     [[maybe_unused]] const std::optional<std::string> i_procedure)
323 {
324     try
325     {
326         if (i_callouts.empty())
327         {
328             createSyncPel(i_errorType, i_severity, i_fileName, i_funcName,
329                           i_internalRc, i_description, i_userData1, i_userData2,
330                           i_symFru, i_procedure);
331             logging::logMessage(
332                 "Callout list is empty, creating PEL without call out");
333             return;
334         }
335 
336         if (m_errorMsgMap.find(i_errorType) == m_errorMsgMap.end())
337         {
338             throw std::runtime_error("Unsupported error type received");
339         }
340 
341         // Path to hold callout inventory path.
342         std::string l_calloutInvPath;
343 
344         uint16_t l_errCode = 0;
345 
346         // check if callout path is a valid inventory path. if not, get the JSON
347         // object to get inventory path.
348         if (std::get<0>(i_callouts[0])
349                 .compare(constants::VALUE_0, strlen(constants::pimPath),
350                          constants::pimPath) != constants::STR_CMP_SUCCESS)
351         {
352             std::error_code l_ec;
353             // implies json dependent execution.
354             if (std::filesystem::exists(INVENTORY_JSON_SYM_LINK, l_ec))
355             {
356                 if (!l_ec)
357                 {
358                     nlohmann::json l_parsedJson = jsonUtility::getParsedJson(
359                         INVENTORY_JSON_SYM_LINK, l_errCode);
360 
361                     if (l_errCode)
362                     {
363                         logging::logMessage(
364                             "Failed to parse JSON file [ " +
365                             std::string(INVENTORY_JSON_SYM_LINK) +
366                             " ], error : " +
367                             commonUtility::getErrCodeMsg(l_errCode));
368                     }
369 
370                     l_calloutInvPath = jsonUtility::getInventoryObjPathFromJson(
371                         l_parsedJson, std::get<0>(i_callouts[0]), l_errCode);
372                 }
373                 else
374                 {
375                     logging::logMessage(
376                         "Error finding symlink. Continue with given path");
377                 }
378             }
379         }
380 
381         if (l_calloutInvPath.empty())
382         {
383             l_calloutInvPath = std::get<0>(i_callouts[0]);
384 
385             if (l_errCode)
386             {
387                 logging::logMessage(
388                     "Failed to get inventory object path from JSON for FRU [" +
389                     std::get<0>(i_callouts[0]) +
390                     "], error : " + commonUtility::getErrCodeMsg(l_errCode));
391             }
392         }
393 
394         const std::map<std::string, std::string> l_additionalData{
395             {"FileName", i_fileName},
396             {"FunctionName", i_funcName},
397             {"DESCRIPTION",
398              (!i_description.empty() ? i_description : "VPD generic error")},
399             {"CALLOUT_INVENTORY_PATH", l_calloutInvPath},
400             {"InteranlRc", std::to_string(i_internalRc)},
401             {"UserData1", ((i_userData1) ? (*i_userData1) : "").c_str()},
402             {"UserData2", ((i_userData2) ? (*i_userData2) : "").c_str()}};
403 
404         const std::string& l_severity =
405             (m_severityMap.find(i_severity) != m_severityMap.end()
406                  ? m_severityMap.at(i_severity)
407                  : m_severityMap.at(types::SeverityType::Informational));
408 
409         auto l_bus = sdbusplus::bus::new_default();
410         auto l_method =
411             l_bus.new_method_call(constants::eventLoggingServiceName,
412                                   constants::eventLoggingObjectPath,
413                                   constants::eventLoggingInterface, "Create");
414         l_method.append(m_errorMsgMap.at(i_errorType), l_severity,
415                         l_additionalData);
416         l_bus.call(l_method);
417     }
418     catch (const std::exception& l_ex)
419     {
420         logging::logMessage(
421             "Sync PEL creation with inventory path failed with error: " +
422             std::string(l_ex.what()));
423     }
424 }
425 
getExceptionData(const std::exception & i_exception)426 types::ExceptionDataMap EventLogger::getExceptionData(
427     const std::exception& i_exception)
428 {
429     types::ExceptionDataMap l_errorInfo{
430         {"ErrorType", types::ErrorType::UndefinedError},
431         {"ErrorMsg", i_exception.what()}};
432 
433     try
434     {
435         if (typeid(i_exception) == typeid(DataException))
436         {
437             const DataException& l_ex =
438                 dynamic_cast<const DataException&>(i_exception);
439             l_errorInfo["ErrorType"] = l_ex.getErrorType();
440             l_errorInfo["ErrorMsg"] =
441                 std::string("Data Exception. Reason: ") + i_exception.what();
442         }
443         else if (typeid(i_exception) == typeid(EccException))
444         {
445             const EccException& l_ex =
446                 dynamic_cast<const EccException&>(i_exception);
447             l_errorInfo["ErrorType"] = l_ex.getErrorType();
448             l_errorInfo["ErrorMsg"] =
449                 std::string("Ecc Exception. Reason: ") + i_exception.what();
450         }
451         else if (typeid(i_exception) == typeid(JsonException))
452         {
453             const JsonException& l_ex =
454                 dynamic_cast<const JsonException&>(i_exception);
455             l_errorInfo["ErrorType"] = l_ex.getErrorType();
456             l_errorInfo["ErrorMsg"] =
457                 std::string("Json Exception. Reason: ") + i_exception.what();
458         }
459         else if (typeid(i_exception) == typeid(GpioException))
460         {
461             const GpioException& l_ex =
462                 dynamic_cast<const GpioException&>(i_exception);
463             l_errorInfo["ErrorType"] = l_ex.getErrorType();
464             l_errorInfo["ErrorMsg"] =
465                 std::string("Gpio Exception. Reason: ") + i_exception.what();
466         }
467         else if (typeid(i_exception) == typeid(DbusException))
468         {
469             const DbusException& l_ex =
470                 dynamic_cast<const DbusException&>(i_exception);
471             l_errorInfo["ErrorType"] = l_ex.getErrorType();
472             l_errorInfo["ErrorMsg"] =
473                 std::string("Dbus Exception. Reason: ") + i_exception.what();
474         }
475         else if (typeid(i_exception) == typeid(FirmwareException))
476         {
477             const FirmwareException& l_ex =
478                 dynamic_cast<const FirmwareException&>(i_exception);
479             l_errorInfo["ErrorType"] = l_ex.getErrorType();
480             l_errorInfo["ErrorMsg"] =
481                 std::string("Firmware Exception. Reason: ") +
482                 i_exception.what();
483         }
484         else if (typeid(i_exception) == typeid(EepromException))
485         {
486             const EepromException& l_ex =
487                 dynamic_cast<const EepromException&>(i_exception);
488             l_errorInfo["ErrorType"] = l_ex.getErrorType();
489             l_errorInfo["ErrorMsg"] =
490                 std::string("Eeprom Exception. Reason: ") + i_exception.what();
491         }
492         else if (typeid(i_exception) == typeid(std::runtime_error))
493         {
494             // Since it is a standard exception no casting is required and error
495             // type is hardcoded.
496             l_errorInfo["ErrorType"] = types::ErrorType::FirmwareError;
497             l_errorInfo["ErrorMsg"] =
498                 std::string("Standard runtime exception. Reason: ") +
499                 i_exception.what();
500         }
501     }
502     catch (const std::exception& l_ex)
503     {
504         logging::logMessage(
505             "Failed to get error info, reason: " + std::string(l_ex.what()));
506     }
507     return l_errorInfo;
508 }
509 
getErrorType(const std::exception & i_exception)510 types::ErrorType EventLogger::getErrorType(const std::exception& i_exception)
511 {
512     const auto& l_exceptionDataMap = getExceptionData(i_exception);
513 
514     auto l_itrToErrType = l_exceptionDataMap.find("ErrorType");
515     if (l_itrToErrType == l_exceptionDataMap.end())
516     {
517         return types::ErrorType::UndefinedError;
518     }
519 
520     auto l_ptrToErrType =
521         std::get_if<types::ErrorType>(&l_itrToErrType->second);
522     if (!l_ptrToErrType)
523     {
524         return types::ErrorType::UndefinedError;
525     }
526 
527     return *l_ptrToErrType;
528 }
529 
getErrorMsg(const std::exception & i_exception)530 std::string EventLogger::getErrorMsg(const std::exception& i_exception)
531 {
532     const auto& l_exceptionDataMap = getExceptionData(i_exception);
533 
534     auto l_itrToErrMsg = l_exceptionDataMap.find("ErrorMsg");
535     if (l_itrToErrMsg == l_exceptionDataMap.end())
536     {
537         return i_exception.what();
538     }
539 
540     auto l_ptrToErrMsg = std::get_if<std::string>(&l_itrToErrMsg->second);
541     if (!l_ptrToErrMsg)
542     {
543         return i_exception.what();
544     }
545 
546     return *l_ptrToErrMsg;
547 }
548 
getErrorTypeString(const types::ErrorType & i_errorType)549 std::string EventLogger::getErrorTypeString(
550     const types::ErrorType& i_errorType) noexcept
551 {
552     const auto l_entry = m_errorMsgMap.find(i_errorType);
553     return (l_entry != m_errorMsgMap.end()
554                 ? l_entry->second
555                 : m_errorMsgMap.at(types::ErrorType::UndefinedError));
556 }
557 } // namespace vpd
558