PLDM:Catching exception precisely and printing it

Correcting catch block in PLDM repo to print all
exception precisely so pldm trace can be more
useful to identify defect easily.

Change-Id: If2e86dcb031ddc2e927e7836d7f4359f5b44cdec
Signed-off-by: Kamalkumar Patel <kamalkumar.patel@ibm.com>
diff --git a/fw-update/update_manager.cpp b/fw-update/update_manager.cpp
index e43d099..0e3128e 100644
--- a/fw-update/update_manager.cpp
+++ b/fw-update/update_manager.cpp
@@ -113,7 +113,7 @@
     }
     catch (const std::exception& e)
     {
-        error("Invalid PLDM package header");
+        error("Invalid PLDM package header: {ERROR}", "ERROR", e);
         activation = std::make_unique<Activation>(
             pldm::utils::DBusHandler::getBus(), objPath,
             software::Activation::Activations::Invalid, this);
diff --git a/host-bmc/dbus_to_host_effecters.cpp b/host-bmc/dbus_to_host_effecters.cpp
index 31a1838..165dab9 100644
--- a/host-bmc/dbus_to_host_effecters.cpp
+++ b/host-bmc/dbus_to_host_effecters.cpp
@@ -189,7 +189,7 @@
     }
     catch (const std::out_of_range& e)
     {
-        error("New state not found in json");
+        error("New state not found in json: {ERROR}", "ERROR", e);
         return;
     }
 
diff --git a/host-bmc/host_pdr_handler.cpp b/host-bmc/host_pdr_handler.cpp
index 86eea92..c309c2a 100644
--- a/host-bmc/host_pdr_handler.cpp
+++ b/host-bmc/host_pdr_handler.cpp
@@ -469,7 +469,7 @@
         }
         // If there is no mapping for terminusHandle assign the reserved TID
         // value of 0xFF to indicate that.
-        catch (const std::out_of_range& e)
+        catch (const std::out_of_range&)
         {
             sensorEntry.terminusID = PLDM_TID_RESERVED;
         }
@@ -863,7 +863,7 @@
                             std::tie(entityInfo, compositeSensorStates) =
                                 lookupSensorInfo(sensorEntry);
                         }
-                        catch (const std::out_of_range& e)
+                        catch (const std::out_of_range&)
                         {
                             try
                             {
@@ -871,7 +871,7 @@
                                 std::tie(entityInfo, compositeSensorStates) =
                                     lookupSensorInfo(sensorEntry);
                             }
-                            catch (const std::out_of_range& e)
+                            catch (const std::out_of_range&)
                             {
                                 error("No mapping for the events");
                             }
diff --git a/libpldmresponder/bios.cpp b/libpldmresponder/bios.cpp
index 6687901..32d68af 100644
--- a/libpldmresponder/bios.cpp
+++ b/libpldmresponder/bios.cpp
@@ -134,9 +134,8 @@
     catch (const sdbusplus::exception_t& e)
     {
         error(
-            "Error getting time, PATH={BMC_TIME_PATH} TIME INTERACE={TIME_INTERFACE}",
-            "BMC_TIME_PATH", bmcTimePath, "TIME_INTERFACE", timeInterface);
-
+            "Error getting time from Elapsed property at '{PATH}' on '{INTERFACE}': {ERROR}",
+            "PATH", bmcTimePath, "INTERFACE", timeInterface, "ERROR", e);
         return CmdHandler::ccOnlyResponse(request, PLDM_ERROR);
     }
 
diff --git a/libpldmresponder/bios_attribute.cpp b/libpldmresponder/bios_attribute.cpp
index 0923ab5..2049512 100644
--- a/libpldmresponder/bios_attribute.cpp
+++ b/libpldmresponder/bios_attribute.cpp
@@ -25,7 +25,7 @@
     {
         readOnly = entry.at("readOnly");
     }
-    catch (const std::exception& e)
+    catch (const std::exception&)
     {
         // No action required, readOnly is initialised to false
     }
@@ -39,7 +39,7 @@
 
         dBusMap = {objectPath, interface, propertyName, propertyType};
     }
-    catch (const std::exception& e)
+    catch (const std::exception&)
     {
         // No action required, dBusMap whill have no value
     }
diff --git a/libpldmresponder/bios_config.cpp b/libpldmresponder/bios_config.cpp
index 1514664..abc7b2a 100644
--- a/libpldmresponder/bios_config.cpp
+++ b/libpldmresponder/bios_config.cpp
@@ -563,8 +563,8 @@
         }
         catch (const std::exception& e)
         {
-            error("Construct Table Entry Error, AttributeName = {ATTR_NAME}",
-                  "ATTR_NAME", attr->name);
+            error("Error constructing table entry for '{ATTR}': {ERROR}",
+                  "ATTR", attr->name, "ERROR", e);
         }
     }
 
@@ -654,8 +654,8 @@
         }
         catch (const std::exception& e)
         {
-            error("Failed to parse JSON config file : {JSON_PATH}", "JSON_PATH",
-                  filePath.c_str());
+            error("Failed to parse JSON config at '{PATH}': {ERROR}", "PATH",
+                  filePath.c_str(), "ERROR", e);
         }
     }
 }
@@ -949,8 +949,8 @@
     }
     catch (const std::invalid_argument& e)
     {
-        error("Could not find handle for BIOS string, ATTRIBUTE={ATTR_NAME}",
-              "ATTR_NAME", attrName.c_str());
+        error("Missing handle for '{ATTR}': {ERROR}", "ATTR", attrName, "ERROR",
+              e);
         return;
     }
 
diff --git a/libpldmresponder/bios_enum_attribute.cpp b/libpldmresponder/bios_enum_attribute.cpp
index dd37057..3f5272f 100644
--- a/libpldmresponder/bios_enum_attribute.cpp
+++ b/libpldmresponder/bios_enum_attribute.cpp
@@ -150,7 +150,7 @@
         auto currentValue = iter->second;
         return getValueIndex(currentValue, possibleValues);
     }
-    catch (const std::exception& e)
+    catch (const std::exception&)
     {
         return defaultValueIndex;
     }
@@ -162,7 +162,7 @@
     {
         return getValueIndex(std::get<std::string>(propValue), possibleValues);
     }
-    catch (const std::exception& e)
+    catch (const std::exception&)
     {
         return getValueIndex(defaultValue, possibleValues);
     }
diff --git a/libpldmresponder/bios_integer_attribute.cpp b/libpldmresponder/bios_integer_attribute.cpp
index 258a188..fa338dc 100644
--- a/libpldmresponder/bios_integer_attribute.cpp
+++ b/libpldmresponder/bios_integer_attribute.cpp
@@ -201,8 +201,9 @@
     }
     catch (const std::exception& e)
     {
-        error("Get Integer Attribute Value Error: AttributeName = {ATTR_NAME}",
-              "ATTR_NAME", name);
+        error(
+            "Error getting integer attribute '{ATTR}' from '{INTERFACE}': {ERROR}",
+            "ATTR", name, "INTERFACE", dBusMap->interface, "ERROR", e);
         return integerInfo.defaultValue;
     }
 }
diff --git a/libpldmresponder/bios_string_attribute.cpp b/libpldmresponder/bios_string_attribute.cpp
index d37da46..77965d3 100644
--- a/libpldmresponder/bios_string_attribute.cpp
+++ b/libpldmresponder/bios_string_attribute.cpp
@@ -89,8 +89,9 @@
     }
     catch (const std::exception& e)
     {
-        error("Get String Attribute Value Error: AttributeName = {ATTR_NAME}",
-              "ATTR_NAME", name);
+        error(
+            "Error getting string attribute '{ATTR}' from '{INTERFACE}': {ERROR}",
+            "ATTR", name, "INTERFACE", dBusMap->interface, "ERROR", e);
         return stringInfo.defString;
     }
 }
diff --git a/libpldmresponder/bios_table.cpp b/libpldmresponder/bios_table.cpp
index 3598277..1b28a53 100644
--- a/libpldmresponder/bios_table.cpp
+++ b/libpldmresponder/bios_table.cpp
@@ -23,7 +23,7 @@
     {
         empty = fs::is_empty(filePath);
     }
-    catch (const fs::filesystem_error& e)
+    catch (const fs::filesystem_error&)
     {
         return true;
     }
diff --git a/libpldmresponder/event_parser.cpp b/libpldmresponder/event_parser.cpp
index 22f88f6..d070758 100644
--- a/libpldmresponder/event_parser.cpp
+++ b/libpldmresponder/event_parser.cpp
@@ -129,8 +129,8 @@
         }
         catch (const std::out_of_range& e)
         {
-            error("Invalid event state {EVENT_STATE}", "EVENT_STATE",
-                  static_cast<unsigned>(state));
+            error("Invalid event state '{EVENT_STATE}': {ERROR}", "EVENT_STATE",
+                  state, "ERROR", e);
             return PLDM_ERROR_INVALID_DATA;
         }
 
@@ -141,14 +141,14 @@
         catch (const std::exception& e)
         {
             error(
-                "Error setting property, ERROR={ERR_EXCEP} PROPERTY={DBUS_PROP} INTERFACE={DBUS_INTF} PATH = {DBUS_OBJ_PATH}",
-                "ERR_EXCEP", e.what(), "DBUS_PROP", dbusMapping.propertyName,
-                "DBUS_INTF", dbusMapping.interface, "DBUS_OBJ_PATH",
-                dbusMapping.objectPath.c_str());
+                "Error setting property value '{PROPERTY}' on interface '{INTERFACE}' at '{PATH}': {ERROR}",
+                "PROPERTY", dbusMapping.propertyName, "INTERFACE",
+                dbusMapping.interface, "PATH", dbusMapping.objectPath, "ERROR",
+                e);
             return PLDM_ERROR;
         }
     }
-    catch (const std::out_of_range& e)
+    catch (const std::out_of_range&)
     {
         // There is no BMC action for this PLDM event
         return PLDM_SUCCESS;
diff --git a/libpldmresponder/fru.cpp b/libpldmresponder/fru.cpp
index 2b2dc23..f8cb6d8 100644
--- a/libpldmresponder/fru.cpp
+++ b/libpldmresponder/fru.cpp
@@ -34,7 +34,7 @@
             entity.entity_type = parser.getEntityType(intfMap.first);
             return entity;
         }
-        catch (const std::exception& e)
+        catch (const std::exception&)
         {
             continue;
         }
@@ -161,8 +161,8 @@
     }
     catch (const std::exception& e)
     {
-        error(
-            "Look up of inventory objects failed and PLDM FRU table creation failed");
+        error("Failed building FRU table due to inventory lookup: {ERROR}",
+              "ERROR", e);
         return;
     }
 
@@ -317,7 +317,7 @@
                               std::back_inserter(tlvs));
                 }
             }
-            catch (const std::out_of_range& e)
+            catch (const std::out_of_range&)
             {
                 continue;
             }
diff --git a/libpldmresponder/fru_parser.cpp b/libpldmresponder/fru_parser.cpp
index eb65966..70f1d9b 100644
--- a/libpldmresponder/fru_parser.cpp
+++ b/libpldmresponder/fru_parser.cpp
@@ -66,7 +66,7 @@
         }
         catch (const std::exception& e)
         {
-            error("FRU DBus lookup map format error");
+            error("FRU DBus lookup map format error: {ERROR}", "ERROR", e);
             throw InternalFailure();
         }
     }
@@ -168,7 +168,7 @@
                 recordMap.emplace(dbusIntfName, recordInfos);
             }
         }
-        catch (const std::exception& e)
+        catch (const std::exception&)
         {
             continue;
         }
diff --git a/libpldmresponder/pdr_numeric_effecter.hpp b/libpldmresponder/pdr_numeric_effecter.hpp
index 88d7f8a..87e4162 100644
--- a/libpldmresponder/pdr_numeric_effecter.hpp
+++ b/libpldmresponder/pdr_numeric_effecter.hpp
@@ -83,7 +83,7 @@
                 }
             }
         }
-        catch (const std::exception& ex)
+        catch (const std::exception&)
         {
             pdr->entity_type = e.value("type", 0);
             pdr->entity_instance = e.value("instance", 0);
diff --git a/libpldmresponder/pdr_state_effecter.hpp b/libpldmresponder/pdr_state_effecter.hpp
index 2a6f86e..f52739e 100644
--- a/libpldmresponder/pdr_state_effecter.hpp
+++ b/libpldmresponder/pdr_state_effecter.hpp
@@ -101,7 +101,7 @@
                 }
             }
         }
-        catch (const std::exception& ex)
+        catch (const std::exception&)
         {
             pdr->entity_type = e.value("type", 0);
             pdr->entity_instance = e.value("instance", 0);
diff --git a/libpldmresponder/pdr_state_sensor.hpp b/libpldmresponder/pdr_state_sensor.hpp
index b75757e..80b829b 100644
--- a/libpldmresponder/pdr_state_sensor.hpp
+++ b/libpldmresponder/pdr_state_sensor.hpp
@@ -104,7 +104,7 @@
                 }
             }
         }
-        catch (const std::exception& ex)
+        catch (const std::exception&)
         {
             pdr->entity_type = e.value("type", 0);
             pdr->entity_instance = e.value("instance", 0);
diff --git a/libpldmresponder/platform.cpp b/libpldmresponder/platform.cpp
index 57315a4..7587a16 100644
--- a/libpldmresponder/platform.cpp
+++ b/libpldmresponder/platform.cpp
@@ -357,6 +357,7 @@
         }
         catch (const std::out_of_range& e)
         {
+            error("Error in handling platform event msg: {ERROR}", "ERROR", e);
             return CmdHandler::ccOnlyResponse(request, PLDM_ERROR_INVALID_DATA);
         }
     }
@@ -432,7 +433,7 @@
             std::tie(entityInfo, compositeSensorStates) =
                 hostPDRHandler->lookupSensorInfo(sensorEntry);
         }
-        catch (const std::out_of_range& e)
+        catch (const std::out_of_range&)
         {
             // If there is no mapping for tid, sensorId combination, try
             // PLDM_TID_RESERVED, sensorId for terminus that is yet to
@@ -444,7 +445,7 @@
                     hostPDRHandler->lookupSensorInfo(sensorEntry);
             }
             // If there is no mapping for events return PLDM_SUCCESS
-            catch (const std::out_of_range& e)
+            catch (const std::out_of_range&)
             {
                 return PLDM_SUCCESS;
             }
diff --git a/oem/ibm/libpldmresponder/file_io.cpp b/oem/ibm/libpldmresponder/file_io.cpp
index b01ef19..bfb2fd1 100644
--- a/oem/ibm/libpldmresponder/file_io.cpp
+++ b/oem/ibm/libpldmresponder/file_io.cpp
@@ -281,9 +281,8 @@
     }
     catch (const std::exception& e)
     {
-        error(
-            "File handle does not exist in the file table, HANDLE={FILE_HANDLE}",
-            "FILE_HANDLE", fileHandle);
+        error("Handle ({HANDLE}) does not exist in the file table: {ERROR}",
+              "HANDLE", fileHandle, "ERROR", e);
         encode_rw_file_memory_resp(request->hdr.instance_id,
                                    PLDM_READ_FILE_INTO_MEMORY,
                                    PLDM_INVALID_FILE_HANDLE, 0, responsePtr);
@@ -376,9 +375,8 @@
     }
     catch (const std::exception& e)
     {
-        error(
-            "File handle does not exist in the file table, HANDLE={FILE_HANDLE}",
-            "FILE_HANDLE", fileHandle);
+        error("Handle ({HANDLE}) does not exist in the file table: {ERROR}",
+              "HANDLE", fileHandle, "ERROR", e);
         encode_rw_file_memory_resp(request->hdr.instance_id,
                                    PLDM_WRITE_FILE_FROM_MEMORY,
                                    PLDM_INVALID_FILE_HANDLE, 0, responsePtr);
@@ -504,9 +502,9 @@
     }
     catch (const std::exception& e)
     {
-        error(
-            "File handle does not exist in the file table, HANDLE={FILE_HANDLE}",
-            "FILE_HANDLE", fileHandle);
+        error("Handle ({HANDLE}) does not exist in the file table: {ERROR}",
+              "HANDLE", fileHandle, "ERROR", e);
+
         encode_read_file_resp(request->hdr.instance_id,
                               PLDM_INVALID_FILE_HANDLE, length, responsePtr);
         return response;
@@ -587,9 +585,8 @@
     }
     catch (const std::exception& e)
     {
-        error(
-            "File handle does not exist in the file table, HANDLE={FILE_HANDLE}",
-            "FILE_HANDLE", fileHandle);
+        error("Handle ({HANDLE}) does not exist in the file table: {ERROR}",
+              "HANDLE", fileHandle, "ERROR", e);
         encode_write_file_resp(request->hdr.instance_id,
                                PLDM_INVALID_FILE_HANDLE, 0, responsePtr);
         return response;
@@ -675,7 +672,8 @@
     }
     catch (const InternalFailure& e)
     {
-        error("unknown file type, TYPE={FILE_TYPE}", "FILE_TYPE", fileType);
+        error("Unknown file type '{FILE_TYPE}': {ERROR} ", "FILE_TYPE",
+              fileType, "ERROR", e);
         encode_rw_file_by_type_memory_resp(request->hdr.instance_id, cmd,
                                            PLDM_INVALID_FILE_TYPE, 0,
                                            responsePtr);
@@ -740,7 +738,8 @@
     }
     catch (const InternalFailure& e)
     {
-        error("unknown file type, TYPE={FILE_TYPE}", "FILE_TYPE", fileType);
+        error("Unknown file type '{FILE_TYPE}': {ERROR}", "FILE_TYPE", fileType,
+              "ERROR", e);
         encode_rw_file_by_type_resp(request->hdr.instance_id,
                                     PLDM_WRITE_FILE_BY_TYPE,
                                     PLDM_INVALID_FILE_TYPE, 0, responsePtr);
@@ -789,7 +788,8 @@
     }
     catch (const InternalFailure& e)
     {
-        error("unknown file type, TYPE={FILE_TYPE}", "FILE_TYPE", fileType);
+        error("Unknown file type '{FILE_TYPE}': {ERROR}", "FILE_TYPE", fileType,
+              "ERROR", e);
         encode_rw_file_by_type_resp(request->hdr.instance_id,
                                     PLDM_READ_FILE_BY_TYPE,
                                     PLDM_INVALID_FILE_TYPE, 0, responsePtr);
@@ -835,6 +835,8 @@
 
     catch (const InternalFailure& e)
     {
+        error("Unknown file type '{FILE_TYPE}': {ERROR}", "FILE_TYPE", fileType,
+              "ERROR", e);
         encode_file_ack_resp(request->hdr.instance_id, PLDM_INVALID_FILE_TYPE,
                              responsePtr);
         return response;
@@ -909,7 +911,8 @@
     }
     catch (const InternalFailure& e)
     {
-        error("unknown file type, TYPE={FILE_TYPE}", "FILE_TYPE", fileType);
+        error("Unknown file type '{FILE_TYPE}': {ERROR}", "FILE_TYPE", fileType,
+              "ERROR", e);
         return CmdHandler::ccOnlyResponse(request, PLDM_INVALID_FILE_TYPE);
     }
 
diff --git a/oem/ibm/libpldmresponder/oem_ibm_handler.cpp b/oem/ibm/libpldmresponder/oem_ibm_handler.cpp
index a910f72..7ab075d 100644
--- a/oem/ibm/libpldmresponder/oem_ibm_handler.cpp
+++ b/oem/ibm/libpldmresponder/oem_ibm_handler.cpp
@@ -513,7 +513,7 @@
         isWatchDogRunning = pldm::utils::DBusHandler().getDbusProperty<bool>(
             watchDogObjectPath, watchDogEnablePropName, watchDogInterface);
     }
-    catch (const std::exception& e)
+    catch (const std::exception&)
     {
         return false;
     }
@@ -591,7 +591,7 @@
     }
     catch (const std::exception& e)
     {
-        error("Error getting the current BMC state");
+        error("Error getting the current BMC state: {ERROR}", "ERROR", e);
         return PLDM_ERROR;
     }
     return PLDM_SUCCESS;
diff --git a/oem/ibm/libpldmresponder/platform_oem_ibm.cpp b/oem/ibm/libpldmresponder/platform_oem_ibm.cpp
index 660b300..432bfd4 100644
--- a/oem/ibm/libpldmresponder/platform_oem_ibm.cpp
+++ b/oem/ibm/libpldmresponder/platform_oem_ibm.cpp
@@ -44,8 +44,7 @@
         }
     }
     catch (
-        const sdbusplus::xyz::openbmc_project::Common::Error::ResourceNotFound&
-            e)
+        const sdbusplus::xyz::openbmc_project::Common::Error::ResourceNotFound&)
     {
         /* Exception is expected to happen in the case when state manager is
          * started after pldm, this is expected to happen in reboot case
diff --git a/pldmd/pldmd.cpp b/pldmd/pldmd.cpp
index fa68f17..8005518 100644
--- a/pldmd/pldmd.cpp
+++ b/pldmd/pldmd.cpp
@@ -129,7 +129,7 @@
             header.command = hdrFields.command;
             if (PLDM_SUCCESS != pack_pldm_header(&header, responseHdr))
             {
-                error("Failed adding response header");
+                error("Failed adding response header: {ERROR}", "ERROR", e);
                 return std::nullopt;
             }
             response.insert(response.end(), completion_code);
diff --git a/requester/mctp_endpoint_discovery.cpp b/requester/mctp_endpoint_discovery.cpp
index c766a70..1a8a6a9 100644
--- a/requester/mctp_endpoint_discovery.cpp
+++ b/requester/mctp_endpoint_discovery.cpp
@@ -32,6 +32,7 @@
     }
     catch (const std::exception& e)
     {
+        error("Failed to call the D-Bus Method: {ERROR}", "ERROR", e);
         return;
     }
 
diff --git a/softoff/softoff.cpp b/softoff/softoff.cpp
index 469c325..2e67db9 100644
--- a/softoff/softoff.cpp
+++ b/softoff/softoff.cpp
@@ -92,7 +92,8 @@
     }
     catch (const std::exception& e)
     {
-        error("PLDM host soft off: Can't get current host state.");
+        error("PLDM host soft off: Can't get current host state: {ERROR}",
+              "ERROR", e);
         hasError = true;
         return PLDM_ERROR;
     }