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/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;
}