catch exceptions as const
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I0bb9caa5bff2c57ea331b9982f279753c44d69d4
diff --git a/app.cpp b/app.cpp
index dbdda96..ccbfe65 100644
--- a/app.cpp
+++ b/app.cpp
@@ -79,7 +79,7 @@
}
}
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
std::cerr << e.what() << "\n";
}
diff --git a/ibm_vpd_app.cpp b/ibm_vpd_app.cpp
index feacc38..377d15b 100644
--- a/ibm_vpd_app.cpp
+++ b/ibm_vpd_app.cpp
@@ -134,7 +134,7 @@
}
}
}
- catch (exception& e)
+ catch (const exception& e)
{
cerr << "Failed to expand location code with exception: " << e.what()
<< "\n";
@@ -266,7 +266,7 @@
{
props.emplace(busProp, itr.value().get<Binary>());
}
- catch (nlohmann::detail::type_error& e)
+ catch (const nlohmann::detail::type_error& e)
{
std::cerr << "Type exception: " << e.what() << "\n";
// Ignore any type errors
@@ -395,7 +395,7 @@
{"Disable line", ::gpiod::line_request::DIRECTION_OUTPUT, 0},
pinValue);
}
- catch (system_error&)
+ catch (const system_error&)
{
cerr << "Failed to set post-action GPIO" << endl;
}
@@ -447,7 +447,7 @@
{"FRU pre-action", ::gpiod::line_request::DIRECTION_OUTPUT, 0},
pinValue);
}
- catch (system_error&)
+ catch (const system_error&)
{
cerr << "Failed to set pre-action GPIO" << endl;
return;
@@ -1132,7 +1132,7 @@
}
}
}
- catch (json::parse_error& ex)
+ catch (const json::parse_error& ex)
{
throw((VpdJsonException("System Json parsing failed",
SYSTEM_JSON)));
@@ -1200,7 +1200,7 @@
{
js = json::parse(inventoryJson);
}
- catch (json::parse_error& ex)
+ catch (const json::parse_error& ex)
{
throw(VpdJsonException("Json parsing failed", jsonToParse));
}
@@ -1275,7 +1275,7 @@
// release the parser object
ParserFactory::freeParser(parser);
}
- catch (exception& e)
+ catch (const exception& e)
{
postFailAction(js, file);
throw;
@@ -1310,7 +1310,7 @@
cerr << ex.what() << "\n";
rc = -1;
}
- catch (exception& e)
+ catch (const exception& e)
{
dumpBadVpd(file, vpdVector);
cerr << e.what() << "\n";
diff --git a/ibm_vpd_utils.cpp b/ibm_vpd_utils.cpp
index b8af0ed..822049c 100644
--- a/ibm_vpd_utils.cpp
+++ b/ibm_vpd_utils.cpp
@@ -239,7 +239,7 @@
present = true;
}
}
- catch (json::parse_error& ex)
+ catch (const json::parse_error& ex)
{
throw(VpdJsonException("Json Parsing failed", INVENTORY_JSON_SYM_LINK));
}
@@ -277,7 +277,7 @@
}
}
}
- catch (json::parse_error& ex)
+ catch (const json::parse_error& ex)
{
throw(VpdJsonException("Json Parsing failed", DBUS_PROP_JSON));
}
@@ -416,7 +416,7 @@
jsonPath += jsonName;
}
- catch (json::parse_error& ex)
+ catch (const json::parse_error& ex)
{
throw(VpdJsonException("Json Parsing failed", SYSTEM_JSON));
}
diff --git a/test/vpd-manager-test/editor_test.cpp b/test/vpd-manager-test/editor_test.cpp
index de7e2ba..7a88c59 100644
--- a/test/vpd-manager-test/editor_test.cpp
+++ b/test/vpd-manager-test/editor_test.cpp
@@ -146,7 +146,7 @@
EditorImpl edit("VINI", "Sn", std::move(vpd));
edit.updateKeyword(dataToUodate, true);
}
- catch (std::runtime_error& e)
+ catch (const std::runtime_error& e)
{
EXPECT_EQ(std::string(e.what()), std::string("Keyword not found"));
}
@@ -165,7 +165,7 @@
EditorImpl edit("VINI", "SN", std::move(vpd));
edit.updateKeyword(dataToUodate, true);
}
- catch (std::runtime_error& e)
+ catch (const std::runtime_error& e)
{
EXPECT_EQ(std::string(e.what()),
std::string("Data updated successfully"));
diff --git a/vpd-manager/server.cpp b/vpd-manager/server.cpp
index 7ca72f6..8fd8476 100644
--- a/vpd-manager/server.cpp
+++ b/vpd-manager/server.cpp
@@ -42,19 +42,21 @@
return o->writeKeyword(path, record, keyword, value);
}));
}
- catch (sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument& e)
+ catch (
+ const sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument&
+ e)
{
return o->_intf->sd_bus_error_set(error, e.name(), e.description());
}
- catch (sdbusplus::com::ibm::VPD::Error::PathNotFound& e)
+ catch (const sdbusplus::com::ibm::VPD::Error::PathNotFound& e)
{
return o->_intf->sd_bus_error_set(error, e.name(), e.description());
}
- catch (sdbusplus::com::ibm::VPD::Error::RecordNotFound& e)
+ catch (const sdbusplus::com::ibm::VPD::Error::RecordNotFound& e)
{
return o->_intf->sd_bus_error_set(error, e.name(), e.description());
}
- catch (sdbusplus::com::ibm::VPD::Error::KeywordNotFound& e)
+ catch (const sdbusplus::com::ibm::VPD::Error::KeywordNotFound& e)
{
return o->_intf->sd_bus_error_set(error, e.name(), e.description());
}
@@ -90,15 +92,17 @@
nodeNumber);
}));
}
- catch (sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument& e)
+ catch (
+ const sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument&
+ e)
{
return o->_intf->sd_bus_error_set(error, e.name(), e.description());
}
- catch (sdbusplus::com::ibm::VPD::Error::LocationNotFound& e)
+ catch (const sdbusplus::com::ibm::VPD::Error::LocationNotFound& e)
{
return o->_intf->sd_bus_error_set(error, e.name(), e.description());
}
- catch (sdbusplus::com::ibm::VPD::Error::NodeNotFound& e)
+ catch (const sdbusplus::com::ibm::VPD::Error::NodeNotFound& e)
{
return o->_intf->sd_bus_error_set(error, e.name(), e.description());
}
@@ -132,15 +136,17 @@
return o->getFRUsByExpandedLocationCode(locationCode);
}));
}
- catch (sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument& e)
+ catch (
+ const sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument&
+ e)
{
return o->_intf->sd_bus_error_set(error, e.name(), e.description());
}
- catch (sdbusplus::com::ibm::VPD::Error::LocationNotFound& e)
+ catch (const sdbusplus::com::ibm::VPD::Error::LocationNotFound& e)
{
return o->_intf->sd_bus_error_set(error, e.name(), e.description());
}
- catch (sdbusplus::com::ibm::VPD::Error::NodeNotFound& e)
+ catch (const sdbusplus::com::ibm::VPD::Error::NodeNotFound& e)
{
return o->_intf->sd_bus_error_set(error, e.name(), e.description());
}
@@ -175,15 +181,17 @@
return o->getExpandedLocationCode(locationCode, nodeNumber);
}));
}
- catch (sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument& e)
+ catch (
+ const sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument&
+ e)
{
return o->_intf->sd_bus_error_set(error, e.name(), e.description());
}
- catch (sdbusplus::com::ibm::VPD::Error::LocationNotFound& e)
+ catch (const sdbusplus::com::ibm::VPD::Error::LocationNotFound& e)
{
return o->_intf->sd_bus_error_set(error, e.name(), e.description());
}
- catch (sdbusplus::com::ibm::VPD::Error::NodeNotFound& e)
+ catch (const sdbusplus::com::ibm::VPD::Error::NodeNotFound& e)
{
return o->_intf->sd_bus_error_set(error, e.name(), e.description());
}
@@ -214,7 +222,9 @@
msg, o->_intf, error,
std::function([=]() { return o->performVPDRecollection(); }));
}
- catch (sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument& e)
+ catch (
+ const sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument&
+ e)
{
return o->_intf->sd_bus_error_set(error, e.name(), e.description());
}
diff --git a/vpd_tool.cpp b/vpd_tool.cpp
index a6087a0..ebb7917 100644
--- a/vpd_tool.cpp
+++ b/vpd_tool.cpp
@@ -138,7 +138,7 @@
}
}
- catch (exception& e)
+ catch (const exception& e)
{
cerr << e.what();
}
diff --git a/vpd_tool_impl.cpp b/vpd_tool_impl.cpp
index 5d35f03..a7cc205 100644
--- a/vpd_tool_impl.cpp
+++ b/vpd_tool_impl.cpp
@@ -301,7 +301,7 @@
output.insert(j.begin(), j.end());
}
}
- catch (exception& e)
+ catch (const exception& e)
{
cerr << e.what();
}
@@ -355,7 +355,7 @@
debugger(output);
}
- catch (json::exception& e)
+ catch (const json::exception& e)
{
json output = json::object({});
json kwVal = json::object({});
@@ -445,7 +445,7 @@
}
edit.updateKeyword(val, updCache);
}
- catch (json::parse_error& ex)
+ catch (const json::parse_error& ex)
{
throw(VpdJsonException("Json Parsing failed", INVENTORY_JSON_SYM_LINK));
}