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.
This commit is contained in:
FiniteSingularity
2025-08-29 11:54:50 -05:00
committed by Ryan Foster
parent 747f67e150
commit a5fa416628

View File

@@ -94,7 +94,15 @@ void PluginManager::loadModules_()
auto modulesFile = getConfigFilePath_();
if (std::filesystem::exists(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();
for (auto it : data) {
ModuleInfo obsModule;