Correct optional JSON config file check
Only clear the config file object when it does not exist and is
optional.
Change-Id: I13bc5a72ac353c0b16ff1557943189ddf1b928d3
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/json_config.hpp b/json_config.hpp
index 883720f..b0acddc 100644
--- a/json_config.hpp
+++ b/json_config.hpp
@@ -104,15 +104,18 @@
confFile = fs::path{confBasePath} / appName / fileName;
}
- if (!fs::exists(confFile) && !isOptional)
+ if (!fs::exists(confFile))
{
- log<level::ERR>("No JSON config file found",
- entry("DEFAULT_FILE=%s", confFile.c_str()));
- throw std::runtime_error("No JSON config file found");
- }
- else
- {
- confFile.clear();
+ if (!isOptional)
+ {
+ log<level::ERR>("No JSON config file found",
+ entry("DEFAULT_FILE=%s", confFile.c_str()));
+ throw std::runtime_error("No JSON config file found");
+ }
+ else
+ {
+ confFile.clear();
+ }
}
return confFile;