catch exceptions as const
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Ic8e6ade739bd5ea6e79cac6b9bb2b182748e10c8
diff --git a/callouts/callout_test.cpp b/callouts/callout_test.cpp
index 729bbf5..fd2cf17 100644
--- a/callouts/callout_test.cpp
+++ b/callouts/callout_test.cpp
@@ -22,7 +22,7 @@
TestCallout::CALLOUT_ERRNO_TEST(0),
TestCallout::CALLOUT_DEVICE_PATH_TEST(argv[1]));
}
- catch (TestCallout& e)
+ catch (const TestCallout& e)
{
commit(e.name());
}
diff --git a/elog_serialize.cpp b/elog_serialize.cpp
index a8b4852..3538bd8 100644
--- a/elog_serialize.cpp
+++ b/elog_serialize.cpp
@@ -125,7 +125,7 @@
}
return false;
}
- catch (cereal::Exception& e)
+ catch (const cereal::Exception& e)
{
log<level::ERR>(e.what());
fs::remove(path);
diff --git a/extensions/openpower-pels/data_interface.hpp b/extensions/openpower-pels/data_interface.hpp
index 2469bb5..fc902a0 100644
--- a/extensions/openpower-pels/data_interface.hpp
+++ b/extensions/openpower-pels/data_interface.hpp
@@ -362,7 +362,7 @@
{
func(_hostUp);
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
using namespace phosphor::logging;
log<level::ERR>("A host state change callback threw "
diff --git a/extensions/openpower-pels/event_logger.hpp b/extensions/openpower-pels/event_logger.hpp
index d1736cc..eed2b81 100644
--- a/extensions/openpower-pels/event_logger.hpp
+++ b/extensions/openpower-pels/event_logger.hpp
@@ -140,7 +140,7 @@
_creator(std::get<msgPos>(event), std::get<levelPos>(event),
std::get<adPos>(event).getData());
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
phosphor::logging::log<phosphor::logging::level::ERR>(
"EventLogger's create function threw an exception",
diff --git a/extensions/openpower-pels/failing_mtms.cpp b/extensions/openpower-pels/failing_mtms.cpp
index 386f496..0e82bd0 100644
--- a/extensions/openpower-pels/failing_mtms.cpp
+++ b/extensions/openpower-pels/failing_mtms.cpp
@@ -49,7 +49,7 @@
unflatten(pel);
validate();
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
log<level::ERR>("Cannot unflatten failing MTM section",
entry("ERROR=%s", e.what()));
diff --git a/extensions/openpower-pels/manager.cpp b/extensions/openpower-pels/manager.cpp
index facaabb..751d15d 100644
--- a/extensions/openpower-pels/manager.cpp
+++ b/extensions/openpower-pels/manager.cpp
@@ -181,7 +181,7 @@
auto policy = service_indicators::getPolicy(*_dataIface);
policy->activate(*pel);
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
// Probably a full or r/o filesystem, not much we can do.
log<level::ERR>("Unable to add PEL to Repository",
@@ -236,7 +236,7 @@
{
data = std::move(eselToRawData(esel));
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
// Try to add it below anyway, so it follows the usual bad data path.
log<level::ERR>("Problems converting ESEL string to a byte vector");
@@ -407,7 +407,7 @@
{
fd = _repo.getPELFD(id);
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
throw common_error::InternalFailure();
}
@@ -446,7 +446,7 @@
{
data = _repo.getPELData(id);
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
throw common_error::InternalFailure();
}
diff --git a/extensions/openpower-pels/pel.cpp b/extensions/openpower-pels/pel.cpp
index a6e4d3d..891436d 100644
--- a/extensions/openpower-pels/pel.cpp
+++ b/extensions/openpower-pels/pel.cpp
@@ -619,7 +619,7 @@
}
}
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
}
diff --git a/extensions/openpower-pels/registry.cpp b/extensions/openpower-pels/registry.cpp
index 34ff268..3f4462f 100644
--- a/extensions/openpower-pels/registry.cpp
+++ b/extensions/openpower-pels/registry.cpp
@@ -694,7 +694,7 @@
return entry;
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
log<level::ERR>("Found invalid message registry field",
entry("ERROR=%s", e.what()));
@@ -726,7 +726,7 @@
{
registry = nlohmann::json::parse(file);
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
log<level::ERR>("Error parsing message registry JSON",
entry("JSON_ERROR=%s", e.what()));
diff --git a/extensions/openpower-pels/repository.cpp b/extensions/openpower-pels/repository.cpp
index 6b9408f..1e9bd6f 100644
--- a/extensions/openpower-pels/repository.cpp
+++ b/extensions/openpower-pels/repository.cpp
@@ -105,7 +105,7 @@
{
write(pel, dirEntry.path());
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
log<level::ERR>(
"Failed to save PEL after updating host state",
@@ -138,7 +138,7 @@
fs::remove(dirEntry.path());
}
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
log<level::ERR>("Hit exception while restoring PEL File",
entry("FILENAME=%s", dirEntry.path().c_str()),
@@ -334,7 +334,7 @@
break;
}
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
log<level::ERR>("Repository::for_each function exception",
entry("ERROR=%s", e.what()));
@@ -350,7 +350,7 @@
{
func(pel);
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
log<level::ERR>("PEL Repository add callback exception",
entry("NAME=%s", name.c_str()),
@@ -367,7 +367,7 @@
{
func(id);
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
log<level::ERR>("PEL Repository delete callback exception",
entry("NAME=%s", name.c_str()),
@@ -406,7 +406,7 @@
attr->second.hostState = state;
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
log<level::ERR>("Unable to update PEL host transmission state",
entry("PATH=%s", attr->second.path.c_str()),
@@ -433,7 +433,7 @@
attr->second.hmcState = state;
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
log<level::ERR>("Unable to update PEL HMC transmission state",
entry("PATH=%s", attr->second.path.c_str()),
diff --git a/extensions/openpower-pels/sbe_ffdc_handler.cpp b/extensions/openpower-pels/sbe_ffdc_handler.cpp
index 4415028..2fe5261 100644
--- a/extensions/openpower-pels/sbe_ffdc_handler.cpp
+++ b/extensions/openpower-pels/sbe_ffdc_handler.cpp
@@ -56,7 +56,7 @@
{
procPos = std::stoi((src6.value()).substr(0, 4));
}
- catch (std::exception& err)
+ catch (const std::exception& err)
{
log<level::ERR>(
fmt::format("Conversion failure errormsg({})", err.what()).c_str());
diff --git a/extensions/openpower-pels/src.cpp b/extensions/openpower-pels/src.cpp
index a9f1b7f..a8694f2 100644
--- a/extensions/openpower-pels/src.cpp
+++ b/extensions/openpower-pels/src.cpp
@@ -218,7 +218,7 @@
return prettyJSON(json);
}
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
log<level::ERR>("Bad JSON from parser",
entry("ERROR=%s", e.what()),
@@ -420,7 +420,7 @@
ccin = std::stoi(ccinString, 0, 16);
}
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
log<level::WARNING>("Could not convert motherboard CCIN to a number",
entry("CCIN=%s", ccinString.c_str()));
@@ -953,7 +953,7 @@
}
}
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
std::string msg =
"Error parsing PEL message registry callout JSON: "s + e.what();
diff --git a/extensions/openpower-pels/tools/peltool.cpp b/extensions/openpower-pels/tools/peltool.cpp
index 5a2abf7..1e8c5b4 100644
--- a/extensions/openpower-pels/tools/peltool.cpp
+++ b/extensions/openpower-pels/tools/peltool.cpp
@@ -85,7 +85,7 @@
{
tmp.yearMSB = std::stoul(token.substr(i, 2), 0, 16);
}
- catch (std::exception& err)
+ catch (const std::exception& err)
{
std::cout << "Conversion failure: " << err.what() << std::endl;
}
@@ -94,7 +94,7 @@
{
tmp.yearLSB = std::stoul(token.substr(i, 2), 0, 16);
}
- catch (std::exception& err)
+ catch (const std::exception& err)
{
std::cout << "Conversion failure: " << err.what() << std::endl;
}
@@ -103,7 +103,7 @@
{
tmp.month = std::stoul(token.substr(i, 2), 0, 16);
}
- catch (std::exception& err)
+ catch (const std::exception& err)
{
std::cout << "Conversion failure: " << err.what() << std::endl;
}
@@ -112,7 +112,7 @@
{
tmp.day = std::stoul(token.substr(i, 2), 0, 16);
}
- catch (std::exception& err)
+ catch (const std::exception& err)
{
std::cout << "Conversion failure: " << err.what() << std::endl;
}
@@ -121,7 +121,7 @@
{
tmp.hour = std::stoul(token.substr(i, 2), 0, 16);
}
- catch (std::exception& err)
+ catch (const std::exception& err)
{
std::cout << "Conversion failure: " << err.what() << std::endl;
}
@@ -130,7 +130,7 @@
{
tmp.minutes = std::stoul(token.substr(i, 2), 0, 16);
}
- catch (std::exception& err)
+ catch (const std::exception& err)
{
std::cout << "Conversion failure: " << err.what() << std::endl;
}
@@ -139,7 +139,7 @@
{
tmp.seconds = std::stoul(token.substr(i, 2), 0, 16);
}
- catch (std::exception& err)
+ catch (const std::exception& err)
{
std::cout << "Conversion failure: " << err.what() << std::endl;
}
@@ -148,7 +148,7 @@
{
tmp.hundredths = std::stoul(token.substr(i, 2), 0, 16);
}
- catch (std::exception& err)
+ catch (const std::exception& err)
{
std::cout << "Conversion failure: " << err.what() << std::endl;
}
@@ -168,7 +168,7 @@
{
num = std::stoul(fileName.substr(fileName.find("_") + 1), 0, 16);
}
- catch (std::exception& err)
+ catch (const std::exception& err)
{
std::cout << "Conversion failure: " << err.what() << std::endl;
}
@@ -428,7 +428,7 @@
foundPEL = true;
}
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
log<level::ERR>("Hit exception while reading PEL File",
entry("FILENAME=%s", fileName.c_str()),
@@ -575,7 +575,7 @@
func(pel, hexDump);
break;
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
std::cerr << " Internal function threw an exception: "
<< e.what() << "\n";
@@ -755,7 +755,7 @@
std::regex scrubRegex(pattern, std::regex::icase);
return scrubRegex;
}
- catch (std::regex_error& e)
+ catch (const std::regex_error& e)
{
if (e.code() == std::regex_constants::error_collate)
std::cerr << "Invalid collating element request\n";
diff --git a/extensions/openpower-pels/user_data_json.cpp b/extensions/openpower-pels/user_data_json.cpp
index 9d331a3..107e026 100644
--- a/extensions/openpower-pels/user_data_json.cpp
+++ b/extensions/openpower-pels/user_data_json.cpp
@@ -344,7 +344,7 @@
return prettyJSON(componentID, subType, version, json);
}
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
log<level::ERR>("Bad JSON from parser",
entry("ERROR=%s", e.what()),
@@ -414,7 +414,7 @@
creatorID);
}
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
log<level::ERR>("Failed parsing UserData", entry("ERROR=%s", e.what()),
entry("COMP_ID=0x%X", componentID),
diff --git a/log_manager.cpp b/log_manager.cpp
index c380429..e9a676a 100644
--- a/log_manager.cpp
+++ b/log_manager.cpp
@@ -434,7 +434,7 @@
create(entry.message(), entry.id(), entry.timestamp(),
entry.severity(), entry.additionalData(), assocs, ffdc);
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
lg2::error(
"An extension's create function threw an exception: {ERROR}",
@@ -502,7 +502,7 @@
return;
}
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
lg2::error("An extension's deleteProhibited function threw an "
"exception: {ERROR}",
@@ -540,7 +540,7 @@
{
remove(entryId);
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
lg2::error("An extension's delete function threw an exception: "
"{ERROR}",
diff --git a/log_manager_main.cpp b/log_manager_main.cpp
index 8f3fab7..bcd0cbe 100644
--- a/log_manager_main.cpp
+++ b/log_manager_main.cpp
@@ -40,7 +40,7 @@
{
startup(iMgr);
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
error("An extension's startup function threw an exception: {ERROR}",
"ERROR", e);
diff --git a/logging_test.cpp b/logging_test.cpp
index d7d82ce..eb0dd21 100644
--- a/logging_test.cpp
+++ b/logging_test.cpp
@@ -105,7 +105,7 @@
example::xyz::openbmc_project::Example::Elog::TestErrorTwo::
DEV_NAME("test case 3"));
}
- catch (example::xyz::openbmc_project::Example::Elog::TestErrorOne& e)
+ catch (const example::xyz::openbmc_project::Example::Elog::TestErrorOne& e)
{
std::cout << "elog exception caught: " << e.what() << std::endl;
}
@@ -152,7 +152,7 @@
TestErrorTwo::DEV_ADDR(0xDEADDEAD), TestErrorTwo::DEV_ID(100),
TestErrorTwo::DEV_NAME("test case 4"));
}
- catch (sdbusplus::exception_t& e)
+ catch (const sdbusplus::exception_t& e)
{
std::cout << "elog exception caught: " << e.what() << std::endl;
}
@@ -211,7 +211,9 @@
example::xyz::openbmc_project::Example::Elog::AutoTestSimple::
STRING("FOO"));
}
- catch (example::xyz::openbmc_project::Example::Elog::AutoTestSimple& e)
+ catch (
+ const example::xyz::openbmc_project::Example::Elog::AutoTestSimple&
+ e)
{
std::cout << "elog exception caught: " << e.what() << std::endl;
commit(e.name());
diff --git a/test/openpower-pels/mocks.hpp b/test/openpower-pels/mocks.hpp
index 6d130ab..57548af 100644
--- a/test/openpower-pels/mocks.hpp
+++ b/test/openpower-pels/mocks.hpp
@@ -182,7 +182,7 @@
std::bind(callback, std::placeholders::_1,
std::placeholders::_2, std::placeholders::_3));
}
- catch (std::exception& e)
+ catch (const std::exception& e)
{
ADD_FAILURE() << "Event exception: " << e.what();
close(fd);
diff --git a/test/openpower-pels/pel_manager_test.cpp b/test/openpower-pels/pel_manager_test.cpp
index bb382b7..eced363 100644
--- a/test/openpower-pels/pel_manager_test.cpp
+++ b/test/openpower-pels/pel_manager_test.cpp
@@ -719,7 +719,9 @@
manager.getPEL(0x50000012 + i);
}
}
- catch (sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument& e)
+ catch (
+ const sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument&
+ e)
{
ADD_FAILURE() << "PELs should have all been found";
}