From 6373728242c6f396232f86cb123a508c38047578 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Sat, 30 Oct 2021 22:31:38 -0500 Subject: [PATCH] JSON write error handling --- scwx-qt/source/scwx/qt/util/json.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/scwx-qt/source/scwx/qt/util/json.cpp b/scwx-qt/source/scwx/qt/util/json.cpp index a0d1cb3d..2ad60651 100644 --- a/scwx-qt/source/scwx/qt/util/json.cpp +++ b/scwx-qt/source/scwx/qt/util/json.cpp @@ -95,15 +95,23 @@ void WriteJsonFile(const std::string& path, { std::ofstream ofs {path}; - if (prettyPrint) + if (!ofs.is_open()) { - PrettyPrintJson(ofs, json); + BOOST_LOG_TRIVIAL(warning) + << logPrefix_ << "Cannot write JSON file: \"" << path << "\""; } else { - ofs << json; + if (prettyPrint) + { + PrettyPrintJson(ofs, json); + } + else + { + ofs << json; + } + ofs.close(); } - ofs.close(); } static void PrettyPrintJson(std::ostream& os,