json: Remove extraneous try/catch
To mediate catching JSON parsing exception after the compatible
interface is already available an extraneous try/catch can be removed so
any JSON parsing exceptions cause the fan apps to crash.
A follow up commit will better handle exceptions, such as JSON parsing
exceptions, in relation to catching and handling the exception thrown
when no config file is able to loaded (whether thru the compatible
interface or not).
Tested:
JSON exception not caught with compatible interface on dbus
Fan control waits for compatible interface when not on dbus and
JSON exception not caught after compatible interface appears on dbus
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
Change-Id: I683c7bb807319f7f0a175fd4c92e573c220bdec5
diff --git a/json_config.hpp b/json_config.hpp
index 129e222..3cb7df2 100644
--- a/json_config.hpp
+++ b/json_config.hpp
@@ -76,55 +76,49 @@
sdbusplus::bus::match::rules::sender(confCompatServ),
std::bind(&JsonConfig::compatIntfAdded, this,
std::placeholders::_1));
- try
+
+ auto compatObjPaths = getCompatObjPaths();
+ if (!compatObjPaths.empty())
{
- auto compatObjPaths = getCompatObjPaths();
- if (!compatObjPaths.empty())
+ for (auto& path : compatObjPaths)
{
- for (auto& path : compatObjPaths)
+ try
{
- try
- {
- // Retrieve json config compatible relative path
- // locations (last one found will be what's used if more
- // than one dbus object implementing the comptaible
- // interface exists).
- _confCompatValues = util::SDBusPlus::getProperty<
- std::vector<std::string>>(util::SDBusPlus::getBus(),
- path, confCompatIntf,
- confCompatProp);
- }
- catch (const util::DBusError&)
- {
- // Compatible property unavailable on this dbus object
- // path's compatible interface, ignore
- }
+ // Retrieve json config compatible relative path
+ // locations (last one found will be what's used if more
+ // than one dbus object implementing the comptaible
+ // interface exists).
+ _confCompatValues =
+ util::SDBusPlus::getProperty<std::vector<std::string>>(
+ util::SDBusPlus::getBus(), path, confCompatIntf,
+ confCompatProp);
}
+ catch (const util::DBusError&)
+ {
+ // Compatible property unavailable on this dbus object
+ // path's compatible interface, ignore
+ }
+ }
+ _loadFunc();
+ _match.reset();
+ }
+ else
+ {
+ // Check if required config(s) are found not needing the
+ // compatible interface, otherwise this is intended to catch the
+ // exception thrown by the getConfFile function when the
+ // required config file was not found. This would then result in
+ // waiting for the compatible interfacesAdded signal
+ try
+ {
_loadFunc();
_match.reset();
}
- else
+ catch (const std::runtime_error&)
{
- // Check if required config(s) are found not needing the
- // compatible interface, otherwise this is intended to catch the
- // exception thrown by the getConfFile function when the
- // required config file was not found. This would then result in
- // waiting for the compatible interfacesAdded signal
- try
- {
- _loadFunc();
- _match.reset();
- }
- catch (const std::runtime_error&)
- {
- // Wait for compatible interfacesAdded signal
- }
+ // Wait for compatible interfacesAdded signal
}
}
- catch (const std::runtime_error&)
- {
- // Wait for compatible interfacesAdded signal
- }
}
/**