Skip to content

Commit

Permalink
Fix a bug that invalid style.json crashes plugin
Browse files Browse the repository at this point in the history
Exception wasn't handled.
  • Loading branch information
ryukau committed Oct 4, 2023
1 parent 77f40e1 commit 3e094cc
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion common/gui/style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ This source is splitted because nlohmann/json.hpp is slow to compile.
*/
#include "style.hpp"
#include "../../lib/ghc/fs_std.hpp"

#define JSON_DIAGNOSTICS 1
#include "../../lib/json.hpp"

#include <algorithm>
Expand Down Expand Up @@ -80,7 +82,13 @@ inline nlohmann::json loadStyleJson()
return data;
}

ifs >> data;
try {
data = nlohmann::json::parse(ifs);
} catch (const nlohmann::json::parse_error &e) {
// output exception information
std::cerr << "Failed to parse `style.json`. Diagnostic message is below.\n"
<< e.what() << std::endl;
}
return data;
}

Expand Down

0 comments on commit 3e094cc

Please sign in to comment.