Răsfoiți Sursa

frontend: Fix plugin manager config loading crash

Current code isn't catching a parse error exception if an invalid config
file is loaded by the plugin manager. This change wraps the plugin
manager config json parse call with a try/catch, and handles invalid
config files by creating a new config file, and logs an error that the
existing config file is invalid.
FiniteSingularity 5 luni în urmă
părinte
comite
a5fa416628
1 a modificat fișierele cu 9 adăugiri și 1 ștergeri
  1. 9 1
      frontend/plugin-manager/PluginManager.cpp

+ 9 - 1
frontend/plugin-manager/PluginManager.cpp

@@ -94,7 +94,15 @@ void PluginManager::loadModules_()
 	auto modulesFile = getConfigFilePath_();
 	auto modulesFile = getConfigFilePath_();
 	if (std::filesystem::exists(modulesFile)) {
 	if (std::filesystem::exists(modulesFile)) {
 		std::ifstream jsonFile(modulesFile);
 		std::ifstream jsonFile(modulesFile);
-		nlohmann::json data = nlohmann::json::parse(jsonFile);
+		nlohmann::json data;
+		try {
+			data = nlohmann::json::parse(jsonFile);
+		} catch (const nlohmann::json::parse_error &error) {
+			modules_.clear();
+			blog(LOG_ERROR, "Error loading modules config file: %s", error.what());
+			blog(LOG_ERROR, "Generating new config file.");
+			return;
+		}
 		modules_.clear();
 		modules_.clear();
 		for (auto it : data) {
 		for (auto it : data) {
 			ModuleInfo obsModule;
 			ModuleInfo obsModule;