JSON write error handling

This commit is contained in:
Dan Paulat 2021-10-30 22:31:38 -05:00
parent b1e1297e0d
commit 6373728242

View file

@ -95,6 +95,13 @@ void WriteJsonFile(const std::string& path,
{ {
std::ofstream ofs {path}; std::ofstream ofs {path};
if (!ofs.is_open())
{
BOOST_LOG_TRIVIAL(warning)
<< logPrefix_ << "Cannot write JSON file: \"" << path << "\"";
}
else
{
if (prettyPrint) if (prettyPrint)
{ {
PrettyPrintJson(ofs, json); PrettyPrintJson(ofs, json);
@ -104,6 +111,7 @@ void WriteJsonFile(const std::string& path,
ofs << json; ofs << json;
} }
ofs.close(); ofs.close();
}
} }
static void PrettyPrintJson(std::ostream& os, static void PrettyPrintJson(std::ostream& os,